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];
Related
I need to align UILabel text center on UINavigationBar. I have implemented all the steps but some how its not center Align. Below is code.
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
titleLabel.backgroundColor = [UIColor clearColor];
[titleLabel setTextColor:[UIColor whiteColor]];
self.titleLabel.text = title;
self.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
self.titleLabel.adjustsFontSizeToFitWidth = NO;
self.titleLabel.adjustsLetterSpacingToFitWidth = NO;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.titleLabel sizeToFit];
float titlePadding = 60.0f;
self.titleLabel.left = titlePadding;
self.titleLabel.width = self.width - 2 * titlePadding;
self.titleLabel.top = ceilf(self.frame.size.height / 2 - self.titleLabel.frame.size.height / 2);
Please help me with this
Try This It will help
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentCenter;
// ^-Use UITextAlignmentCenter for older SDKs.
label.textColor = [UIColor yellowColor]; // change this color
self.navigationItem.titleView = label;
label.text = NSLocalizedString(#"PageThreeTitle", #"");
[label sizeToFit];
How can I set/customize setTitleVerticalPositionAdjustment in iOS 4.0? I need suggestion.
- (void)viewDidLoad
{
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentRight;
label.textColor=[UIColor whiteColor];
label.font = [ UIFont fontWithName: #"XXII DIRTY-ARMY" size: 32.0 ];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.0f];
label.text=NSLocalizedString(#"HomeTitle", #"Home");
self.navigationController.navigationBar.tintColor = [UIColor newBrownLight];
label.frame=CGRectMake(0, 0, 290, 44);
self.navigationItem.titleView = label;
self.navigationItem.title=label.text;
}
I have a label that I want to use it in few places. It has nothing more than the following custom settings
label.font = [UIFont fontWithName:#"Arial" size:12.0];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.userInteractionEnabled = YES;
label.textColor = [UIColor whiteColor];
Now I am wondering, do I need to introduce a subclass (of UILabel) specifically for it? Since it's used in multiple places, what would be the best design pattern for this kind of usage?
personally, i wouldn't create a subclass in this case. there are a variety of things you can do... you could create a category. e.g. in the .h
#interface UILabel (MyLabel)
+ (UILabel *)createMyLabelWithFrame;
#end
and in the .m:
#implementation UILabel (MyLabel)
+ (UILabel *)createMyLabelWithFrame:(CGRect)frame {
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.font = [UIFont fontWithName:#"Arial" size:12.0];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.userInteractionEnabled = YES;
label.textColor = [UIColor whiteColor];
return label;
}
I would use either a category or just a basic function on some available class. Subclassing creates significantly more work. i.e. Constantly having to change the class in IB or changing all the code throughout the project.
Category could look like this:
#implementation UILabel (FormatMyLabels)
-(void)useMySpecialFormatting{
self.font = [UIFont fontWithName:#"Arial" size:12.0];
self.textAlignment = UITextAlignmentCenter;
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = YES;
self.textColor = [UIColor whiteColor];
}
#end
And you would use it like:
[self.myFirstLabel useMySpecialFormatting];
Function could look like this:
-(void)useSpecialFormattingOnLabel:(UILabel *)label{
label.font = [UIFont fontWithName:#"Arial" size:12.0];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.userInteractionEnabled = YES;
label.textColor = [UIColor whiteColor];
}
And you would use this like:
[ClassOrInstanceWithFunction useSpecialFormattingOnLabel:self.myFirstLabel];
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.).
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];