Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

UISegmentedControl #12

Closed
2 of 3 tasks
youknowone opened this issue Jun 17, 2013 · 26 comments
Closed
2 of 3 tasks

UISegmentedControl #12

youknowone opened this issue Jun 17, 2013 · 26 comments
Labels
Milestone

Comments

@youknowone
Copy link
Owner

  • Dynamic patch
  • Flatten
  • Fine tuning
@mruegenberg
Copy link

I get a crash with the latest version on Cocoapods (0.0.12) in UI7SegmentedControl, l. 57.

The crash happens because the attributes dictionary gets built with self.tintColor, which is nil for some reason.

@youknowone
Copy link
Owner Author

Thank you for report. Which version of iOS did you tried?

@mruegenberg
Copy link

This was on the iOS 6.1 Simulator.

youknowone added a commit that referenced this issue Jun 22, 2013
@youknowone
Copy link
Owner Author

Though I could not represent this problem, I found a hole in UI7View and fixed it.

@kovpas
Copy link

kovpas commented Jun 27, 2013

The problem is that for some reason -[UISegmentedControl tintColor] returns _UISegmentedControlAppearanceStorage instead of UIColor after any of appearance methods is invoked (i.e. -[UISegmentedControl setBackgroundImage:forState:barMetrics:]). Solution is to save UIColor instance first and then use this saved value within _segmentedControlInit method. For me this fixed crash.

youknowone added a commit that referenced this issue Jun 30, 2013
@youknowone
Copy link
Owner Author

@kovpas ab5b667 fixed it like your patch?

@kovpas
Copy link

kovpas commented Jun 30, 2013

@youknowone yep, thanks!

@hamadeguchi
Copy link

Crashes on real machine(runs successfully on simulator)
line 73:

    [self setDividerImage:self.tintColor.image
      forLeftSegmentState:UIControlStateNormal
        rightSegmentState:UIControlStateNormal
               barMetrics:UIBarMetricsDefault];

I traced logic, then I found difference between real and simulator.
Line 59 of UI7View.m

[self __tintColor]

returns nil on simulator. return non nil on real machine.
so I commented next if clause.
which is the best way to fix it?

the exception is following;
[_UISegmentedControlAppearanceStorage image]: unrecognized selector sent to instance XXXXX

@youknowone
Copy link
Owner Author

@hamadeguchi Thank you for report! I fixed it and released new version.

@hamadeguchi
Copy link

Thank you for your quick response. I confirmed it solved!

FYI:
UI7BarButtonItem.m:118:12: Instance method '-_tintColor' not found (return type defaults to 'id')

@youknowone
Copy link
Owner Author

Warning also removed. It will be included in next release.

@gabrielribeiro
Copy link

I have a problem with this control when using in iPod 4th with iOS6. The segmented control present just a line in the middle of the text, very ugly.

@youknowone
Copy link
Owner Author

@gribeiro-mobirama Sorry. Because I don't have iPod 4th, I couldn't test this control on it. Could you represent it on simulator? Or show me representable code for that?

@gabrielribeiro
Copy link

Yes, in iPhone Simulator in Xcode DP2:

ios simulator screen shot 06 07 2013 09 30 42

My code:

NSDictionary * selectedAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor],
                                                   UITextAttributeTextColor,
                                                   nil];

    NSDictionary * deselectedAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                     [UIColor redColor],
                                                     UITextAttributeTextColor,
                                                     nil];

    [segmentedControl setTitleTextAttributes:deselectedAttributesDictionary forState:UIControlStateNormal];
    [segmentedControl setTitleTextAttributes:selectedAttributesDictionary forState:UIControlStateSelected];

for (int i = 0; i < [segmentedControl.subviews count]; i++)
    {
        [[segmentedControl.subviews objectAtIndex:i] setTintColor:[UIColor redColor]];
    }

youknowone added a commit that referenced this issue Jul 6, 2013
@youknowone
Copy link
Owner Author

Unfortunately, I tried this code but didn't get that ugly stroke. (Test code is included current HEAD) But I found you are setting subview's tint colors. UI7Kit is implemented with all other codes, but is not touching subviews. How about try to set entier tint color like:

[segmentedControl setTintColor:[UIColor redColor]]

In your method, it will not change entire color theme but will change only partial parts.

About the stroke, I need more information. Try test app of current HEAD and check the #12 row in main table view. Test code is here: https://github.com/youknowone/UI7Kit/blob/master/UI7KitTestApp/UITIssue12ViewController.m#L30

@gabrielribeiro
Copy link

Thanks a lot man! I did like you did, initializing the segmentedcontrol in ViewDidLoad with frame size. That worked fine, but in iOS6, just blue, not red. In iOS7, the red tint color worked normally. And clue about this tint color in iOS6? Am I doing shit again?

@youknowone
Copy link
Owner Author

setTintColor: should work well in both OS. But it is fixed in recent days. So you may using unfixed UI7Kit yet. I updated UI7Kit just now. Try updating this.

If it still does not work after updating, it is UI7Kit bug. Please let me know it.

@gabrielribeiro
Copy link

Thanks a lot! That worked fine! Great job!

@youknowone
Copy link
Owner Author

@gribeiro-mobirama I found iOS7 SDK + Interface Builder + 3.5 inch screen can make this problem. Is this right? I didn't noticed this because i tested all the code from iOS6 SDK.

@gabrielribeiro
Copy link

Yes. That ugly stroke just happened with me when under these conditions. If you could fix it, would be nice for others. To me, creating the segmetedcontrol programatically resolved. 👍

@youknowone
Copy link
Owner Author

It is iOS7 SDK bug. (Without UI7Kit, it still is broken)
I think watching next beta is better at this time. If this would not fixed until release of iOS7, I will add a workaround.

@jozsi
Copy link

jozsi commented Jul 25, 2013

screen shot 2013-07-25 at 7 22 57 pm

First one is added from Interface Builder & Autolayout. Stroke appears.
Second is added programatically.

Without Autolayout it's ok.
screen shot 2013-07-25 at 7 28 02 pm

@youknowone
Copy link
Owner Author

Interesting information. Thank you @tracid

youknowone added a commit that referenced this issue Jul 31, 2013
@youknowone
Copy link
Owner Author

@gribeiro-mobirama @tracid I prevented UISegmentedControl's height become less than 1px. I found this helps problems, at least in some case.

@jozsi
Copy link

jozsi commented Jul 31, 2013

Meanwhile I've updated to iOS7 SDK & Xcode 5 DP4. Running on the iOS 6.1 simulator, 0.6.1 still doesn't fix the problem (UISegmentedControl added to an autolayout XIB). But setting a constraint on the height to 29 works the problem around.

@youknowone
Copy link
Owner Author

Depressing... I may should add constraint in the initWithCoder: for iOS6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants