UISegmentedControl always appears dim - ios

No matter what settings I try, I cannot get UISegmentedControl to render with the tintColor I set. I took a few screenshots, and it seems whatever color I set, the rendered result is 20% darker (i.e. UIColor whiteColor ends up R:204,G:204,B:204)
I've tried every combination of the settings below, and nothing seems to change the fact it always looks darker. However, inspection of the tintAdjustmentMode at all stages before/after setting the values, appear, etc. comes out as UITintAdjustmentModeNormal. I can make the background color of the text render at full brightness, but the frame and selected index fill is always at 80% brightness. Oddly, this doesn't happen in the 7.1 Simulator, but it does happen on my iPhone 5 with 7.1.1.
Has anyone had similar problems? I've read many other threads about controls not dimming, or people wanting to set different colors for different parts of the control, but couldn't find any about tintColors that won't show at full brightness.
Various settings I've tried individually and together:
UIColor *tintColorToSet = [UIColor colorWithRed:0/255.0f green:241/255.0f blue:1.0f alpha:1.0f];
NSMutableDictionary *textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
tintColorToSet, NSForegroundColorAttributeName,
[UIColor clearColor], NSBackgroundColorAttributeName,
[UIFont fontWithName:#"NesController" size:18.0f], NSFontAttributeName, nil];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[textAttributes setValue:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateSelected];
_lengthBar.tintColor = tintColorToSet;
_lengthBar.alpha = 1.0f;
_lengthBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Thanks for the help.

Related

Color Palettes from storyboard used programmatically

I am building an app and I have multiple colors that I want a background to be depending on a predetermined factor. In my story boar I have tested and chosen the colors I wanted to use and I have put them in a palette on the color picker. First question can I programmatically call on the colors of the palette.
if that doesn't work I have already gotten the RGB values for each of the colors but when I try to go do this:
UIColor *myBlue =[UIColor colorWithRed:(60/255) green:(97/255) blue:(255/255) alpha:1.000];
self.navigationController.navigationBar.barTintColor = myBlue;
self.tabBarController.tabBar.barTintColor = myBlue;
it gives me the same color as of I go
[UIColor blueColor]
the reason I am creating my own color is because I don't want the predetermined colors but they are not showing up.
(This might be a zombie issue, but for anyone else curious)
This is actually a bug because you're performing integer division instead of floating point division. Dividing an int by an int throws away the remainder. You're code is functionally equivalent to:
UIColor *myBlue =[UIColor colorWithRed:0 green:0 blue:1 alpha:1.000];
Which of course is pure blue. To fix, force floating point division by making one of the numbers a float type. For example, you could change that line to:
UIColor *myBlue =[UIColor colorWithRed:(60/255.0) green:(97/255.0) blue:(255/255.0) alpha:1.000];

FontAwesome for UITTabBarController

I am working on building a mobile app to compliment a website and I need to mimic the icons used on the site. The icons are from FontAwesome and I want them to appear as my UITabBar Items. I have successfully installed the FontAwesome into my project and then I was able to add the icon into a label, but I can't figure out how to get the icon to render in my tab bar item.
The code I used to render the icon in the label:
self.label.font = [UIFont fontWithName:#"FontAwesome" size:12];
self.label.text = [NSString stringWithFormat:#"%#", #"\uf007"];
I have also tried typing in "\uf007" into the title of the icon, and then changing the font in my viewDidLoad method, but that did not work. Thank you for any help!
EDIT
My reputation is below 10 so the link to the image is: uitabbaritem
In the image above, I am manually typing in the code I want to show. If I change the font to FontAwesome, the text stays the same.
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
[UIFont fontWithName:#"font" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateHighlighted];
Reference - iOS5 TabBar Fonts and Color

Remove tint on TableView iOS 7

I am trying to remove the white view behind the alphabet indexer but have had no luck.
I am trying to make it clear but nothing has worked for me so far.
sectionIndexBackgroundColor is what your looking for. You can do something like this,
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
If you want to change the color of the highlighted state, use the following property.
tableView.sectionIndexTrackingBackgroundColor = [UIColor redColor];
Keep in mind that sectionIndexBackgroundColor became available in iOS7. So if your supporting iOS6 you might want to call something like this.
if ([tableView respondsToSelector:#selector(sectionIndexBackgroundColor)]) {
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
}

UIBarButtonItem: how can I change the text shadow offset?

I'm trying to change the offset of the shadow behind the text in a UIBarButtonItem.
This is my code:
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithWhite:0.30 alpha:1.0] forKey:UITextAttributeTextColor];
[attributes setValue:[UIColor whiteColor] forKey:UITextAttributeTextShadowColor];
[attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
Changing the text color works. Changing the shadow color works. Changing the shadow offset doesn't seem to do anything.
Is something wrong with the way I'm doing this? I've also tried setting it directly, without the appearance proxy, but that didn't work either.
I believe your code is correct though perhaps you expect something different from what it does. If I paste it into a test app and change the offset values to 10.0, 10.0 the shadow offset is visible for me. (iOS 5.0)
Your shadow UIOffset values are 0.0,0.0 which effectively causes no shadow. You will need to offset the shadow by at least 1 pixel in any direction. eg. this will give you a shadow to the bottom left side.
[NSValue valueWithUIOffset:UIOffsetMake(-1.0, 1.0)]

How to change the font size of the text on a UISegmentedControl?

Following is the code for initializing my UISegmentedControl.
- (void)initializeToolButtons
{
NSArray *buttonTitles = [NSArray arrayWithObjects:#"ANNEXET", #"HOVET", #"GLOBEN", "ALL", nil];
toolbuttons = [[UISegmentedControl alloc] initWithItems:buttonTitles];
toolbuttons.segmentedControlStyle = UISegmentedControlStyleBar;
toolbuttons.tintColor = [UIColor darkGrayColor];
toolbuttons.backgroundColor = [UIColor blackColor];
toolbuttons.frame = CGRectMake(0, 0, 320, 30);
[toolbuttons addTarget:self action:#selector(toolButtonsAction) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:toolbuttons];
}
How can I reduce the font size for each item on the UISegmentedControl?
Note: toolButtons has already been declared globally.
Very simple:
UIFont *Boldfont = [UIFont boldSystemFontOfSize:16.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:Boldfont forKey:UITextAttributeFont];
[segment setTitleTextAttributes:attributes forState:UIControlStateNormal];
Consider re-designing your interface or use the "tab" style which has a smaller font. Messing with unexposed properties might get your app rejected or break your app if they change something under the hood.
For example the code sample given doesn't work. When you tap on a segment the font for that segment gets reset to its normal size. Anything unpredictable can happen or change in your app if you do things that deviate from the normal useage of these things. So if you want an app that will continue working in following OS updates stick with the standard stuff, or make your own controls with UIButtons and rectangular background images. A hack might work now, but its not to say it will in the future.

Resources