ios - Changing the tint color for only the selected segment in swift -


I am doing one of my projects faster than Objective-C and I have a function that I -I use that I can not translate properly

This object is C code

  - (zero) Segment action: (UISegmentedControl *) Sender {NSLog (@ "Segment"); For (int e = 0; e & lt; [counter.subview count]; e ++) {if ([[sender.subviews objectAtIndex: e] isSelected]) {[[sender.subviews objectAtIndex: e] setTintColor: [UIColor colorWithPatternImage [UIImage imageNamed: @ "gradient.png"]]]; } Other {[[Sender subviews itemAddindex: E] SettentColor: zero]; }}}  

And this is where I am fast

  func segChanged (Sender: UISegmentedControl) {println ("Value changed") var E: Int = 0 var countOfSeg = sender.subviews.count (e = 0; e & lt; countOfSeg; e ++) {} print (sender.svviews [e])}  

For this statement put .selected at the end of sender.subviews [E] .

"text" itemprop = "text">

subviews is an array of anyObjects, then you have to cast each item to UIControl To do this, you can refer to your selected / before / code> property:

  item in control.subviews {if SubView = Item is given? UIControl {if subview.selected {...}}}  

Edit: It compiles, but does not work on runtime In iOS 8, it seems that control subviews Examples of a private UISegment class, which is actually the subclass of UIImageView. The attempt to put each item in UIContole will fail silently. I'm not sure why this was working in iOS 7 or Apple has changed how UISegmentedControl is created, or UIImageView is a personal selected property that is not what you are trying to do That is I recommend that you implement this effect in any other way, which means that creating a custom version of the fragmented control, if you really want to continue using internal subviews, then change "UIControl" "if subview.highlighted ... "to" UIImageView "and change" if subview.selected ... "to do. Just keep in mind that this can not work on iOS 7, and later versions of iOS can break in again.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -