How do I get the UIToolbar font to match UINavigation Controller? - iphone

Using the following post, I was able to add a UILabel to a UIToolbar, however, it looks crappy. Anyone know how to get the text size / color / shadow to match the title for a UINavigationController?
Navigation Controller
alt text http://www.codingwithoutcomments.com/uploads/Picture1.png
UIToolbar with UILabel
alt text http://www.codingwithoutcomments.com/uploads/Picture2.png
What steps do I need to take to make them match?

You might also want to add a shadow?
itemLabel.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
itemLabel.shadowOffset = CGSizeMake(0, -1.0);

Obviously the question is about iPhone, but in case anyone is wondering, here are the numbers for iPad:
titleLabel.font = [UIFont boldSystemFontOfSize:20.0];
titleLabel.shadowOffset = CGSizeMake(0, 1);
titleLabel.shadowColor = [UIColor colorWithWhite:1.f alpha:.5f];
titleLabel.textColor = [UIColor colorWithRed:113.f/255.f green:120.f/255.f blue:127.f/255.f alpha:1.f];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = #"Title";

UILabel * itemLabel = [[UILabel alloc] initWithFrame:rectArea];
itemLabel.text = #"Item";
itemLabel.textColor = [UIColor whiteColor];
itemLabel.font = [UIFont boldSystemFontOfSize:22.0];

Related

Easier way to change all the buttons?

I have 10 UIButtons that I want to change the background color of.
Here's what I have right now:
b1.backgroundColor = [UIColor redColor];
b2.backgroundColor = [UIColor redColor];
b3.backgroundColor = [UIColor redColor];
b4.backgroundColor = [UIColor redColor];
b5.backgroundColor = [UIColor redColor];
b6.backgroundColor = [UIColor redColor];
b7.backgroundColor = [UIColor redColor];
b8.backgroundColor = [UIColor redColor];
b9.backgroundColor = [UIColor redColor];
b10.backgroundColor = [UIColor redColor];
I wonder if there is another, simpler, way of doing this. I have all ready tried UIButton.backgroundColor = [UIColor redColor] but that didn't work.
//Make an array of the buttons:
NSArray* buttons=[[NSArray alloc] initWithObjects:b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,nil];
//Loop through them
for(UIButton* b in buttons)
{
b.backgroundColor = [UIColor redColor];
}
The array could also be initialized in viewDidLoad.
Put the buttons in an array:
NSArray* buttonArray=[[NSArray alloc] initWithObjects:b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,nil];
Then set the background color for all the buttons:
[buttonArray makeObjectsPerformSelector:#selector(setBackgroundColor:) withObject:[UIColor redColor]];
Create an array of your buttons in viewDidLoad. Then just use a for loop to change colors.

What is the font size, font color, shadow color & offset in UITableView section header?

I am reproducing the original UITableView section header using custom graphics.
What is the font size, font color, shadow color & offset in UITableView section header ?
Thanks.
Try this formula:
headerLabel.font = [UIFont boldSystemFontOfSize:17];
headerLabel.shadowColor = [UIColor colorWithWhite:1.0 alpha:1.0];
headerLabel.shadowOffset = CGSizeMake(0, 1);
headerLabel.textColor = [UIColor colorWithRed:0.265 green:0.294 blue:0.367 alpha:1.0];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:20];
headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
Hope this will fulfill your requirements...
If you mean the pre-iOS7 look, I got good results with:
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] init];
headerView.textLabel.text = title;
headerView.textLabel.textColor = [UIColor whiteColor];
headerView.textLabel.shadowColor = [UIColor colorWithRed:0.40 green:0.42 blue:0.43 alpha:1.0];
headerView.textLabel.shadowOffset = CGSizeMake(0, 1);
If you're not using UITableViewHeaderFooterView, then create one as a test and grab its label's other attributes (font, etc.).

iPhone Background Image for Table Cell

How can I make the background of the accessory clear? I've managed to set the rest of the elements to [UIColor clearcolor] but it doesn't work for the accessory...
Here's what my progress looks like:
[self.accessoryView setOpaque: NO];
self.accessoryView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Icon.png"]];
self.accessoryView.backgroundColor = [UIColor clearColor];
Thanks for any help you guys can offer!
have you tried
cell.accessoryView.backgroundColor = [UIColor clearColor];

Style UIlabel text like the font in the Settings panel

How do you style a UILabel text like the text below (created using titleForFooterInSection)?
Use the below , you might need to alter the values of color and Size, Try with different-2 combination of both..
UILabel* label = [[UILabel alloc] init];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(0,1);
See the UILabel Documentation.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:14];
label.shadowColor = [UIColor colorWithWhite:1 alpha:0.5];
label.shadowOffset = CGSizeMake(1,1);
label.textColor = [UIColor colorWithRed:(76.0f/255.0f) green:(86.0f/255.0f) blue:(108.0f/255.0f) alpha:1.0f];

Customizing Title in the NavigationBar for a ABPeoplePickerNavigationController

I have created an AddressBook kind of application where I display a list of people in a UITableView, when a person is selected an ABUnknownPersonViewController is pushed. From this ABUnknownPersonViewController the user is able (by using the built in functionality) to either add the person to a "New Contact" or "Existing Contact".
This is where my problem is located. I am using a Custom UILabel for the NavigationBar title throughout my application. And I need to be able to do this for the views that are pushed by "Add New Contact" / "Add to Existing Contact" as well.
I solved this for the "Add New Contact" by creating a category for ABNewPersonViewController, but the same approach doesn't work for the "Add to Existing Contact". I guess this might be due to the fact that is it an ABPersonPickerNavigationController that is pushed.
#implementation ABPeoplePickerNavigationController (customTitle)
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationBar.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
}
The change of color for the NavigationBar's tintColor works fine, but I cant find a proper way to access the title. Help that include a working example where you are able to change the title in a ABPeoplePickerNavigationController that is pushed from a ABUnknownPersonViewController would be much appriciated.
This is how the category for ABNewPersonViewController (that works) looks like:
#implementation ABNewPersonViewController (customTitle)
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
}
-(void)setTitle:(NSString *)theTitle {
CGRect frame = CGRectMake(0, 0, 45, 45);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:255.0 alpha:1];
label.shadowOffset = CGSizeMake(1, 1);
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithRed:23/255.0 green:23/255.0 blue:23/255.0 alpha:1];
self.navigationItem.titleView = label;
label.text = theTitle;
[label sizeToFit];
}
#end
I use custom labels for this purpose. You can also change font size with this code.
Example:
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 320 / 11)];
label.font = 16.0;
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.text = #"Your title";
self.navigationItem.titleView = label;
[label release];
Hope this helps.