I'm trying to code the appearance of an UILabel, but I can't get another font applied. The funny (or rather annoying) thing is that if I add a second UILabel, the font WILL BE APPLIED for the second label, BUT NOT the first. I'm slightly going crazy on this... especially the font size won't change if I try to.
My code (found in my ViewDidLoad):
NSString* dateWeekDay = #"MON";
CGRect dateWeekDayFrame = CGRectMake(183, 12, 34, 21);
viewNoteDateWeekDay = [[UILabel alloc] initWithFrame:dateWeekDayFrame];
viewNoteDateWeekDay.text = dateWeekDay;
viewNoteDateWeekDay.textColor = [UIColor blackColor];
viewNoteTitle.font = [UIFont fontWithName:#"Helvetica Neue" size:70.0f]; // I know this size is crazy, but it's just to show that it has no effect whatsoever...
viewNoteDateWeekDay.transform = CGAffineTransformMakeRotation( ( -90 * M_PI ) / 180 );
viewNoteDateWeekDay.backgroundColor = [UIColor clearColor];
NSString* dateDay = #"01";
CGRect dateDayFrame = CGRectMake(209, 3, 47, 50);
viewNoteDateDay = [[UILabel alloc] initWithFrame:dateDayFrame];
viewNoteDateDay.text = dateDay;
viewNoteDateDay.textColor = [UIColor blackColor];
viewNoteDateDay.font = [UIFont fontWithName:#"Helvetica Neue" size:33.0f];
viewNoteDateDay.backgroundColor = [UIColor clearColor];
NSString* dateMonth = #"SEPTEMBER";
CGRect dateMonthFrame = CGRectMake(249, 6, 93, 31);
viewNoteDateMonth = [[UILabel alloc] initWithFrame:dateMonthFrame];
viewNoteDateMonth.text = dateMonth;
viewNoteDateMonth.textColor = [UIColor blackColor];
viewNoteDateMonth.font = [UIFont fontWithName:#"Helvetica Neue" size:12.0f];
viewNoteDateMonth.backgroundColor = [UIColor clearColor];
You are specifying the wrong variable name when you're setting the font property. Your code says: viewNoteTitle.font = ... when it should read viewNoteDateWeekDay.font = ...
Related
I am using this calendar for my application.
Question : how to resize the frame of this calendar. I tried one by doing this
calendar = [[TKCalendarMonthView alloc] init];
calendar.delegate = self;
calendar.frame = CGRectMake(0, 0, 200, calendar.frame.size.height);
However it is still shown as width of 360
Does anybody have any clues how to do this
You won't be able to change the width of the month view (tiles) without making a lot of changes to TKCalendarMonthViewController. For example, the width of each individual tile/day is set to 46 in the -(id)initWithSundayAsFirst method.
int i = 0;
for(NSString *s in ar){
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46 * i, 29, 46, 15)];
[self addSubview:label];
label.text = s;
label.textAlignment = UITextAlignmentCenter;
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0, 1);
label.font = [UIFont systemFontOfSize:11];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];
i++;
}
You'll notice that images are used to for the backgrounds of individual tiles in many of the methods, so you would need to create images suitable for your custom width. For example -(void)reactToTouch:down contains:
self.selectedImageView.image = [UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile Selected.png")];
need to add a downward facing arrow to a text box. decided to use the rightViewMode to display it. it works for the first textfield i use, but does not show up in the second. it happens in 3 different views where i need to do this.
code:
//added to post
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
UIView *rightPaddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
UIImageView *unitArrowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"prev-arrow.png"]];
unitArrowImage.frame = CGRectMake(0, 0, 20, 20);
[unitArrowImage setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[rightPaddingView addSubview:unitArrowImage];
//other code
UITextField *seedRateUnitTextField = [[UITextField alloc] initWithFrame:myRect];
seedRateUnitTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
seedRateUnitTextField.placeholder = #"Unit";
seedRateUnitTextField.borderStyle = UITextBorderStyleLine;
seedRateUnitTextField.backgroundColor = [UIColor whiteColor];
seedRateUnitTextField.textColor = [UIColor textFieldTextColor];
seedRateUnitTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
seedRateUnitTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
seedRateUnitTextField.layer.borderWidth = 1.0f;
seedRateUnitTextField.leftView = paddingView;
seedRateUnitTextField.leftViewMode = UITextFieldViewModeAlways;
seedRateUnitTextField.rightView = rightPaddingView;
seedRateUnitTextField.rightViewMode = UITextFieldViewModeAlways;
seedRateUnitTextField.delegate = self;
seedRateUnitTextField.tag = 0;
[myScrollView addSubview:seedRateUnitTextField];
[self.dataSetDictionary setValue:seedRateUnitTextField forKey:#"seedRateUnitData"];
myRect = CGRectMake(200, ((4 * 40) + 140), 170, 30);
UITextField *plantingDepthTextField = [[UITextField alloc] initWithFrame:myRect];
plantingDepthTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
plantingDepthTextField.placeholder = #"Enter Planting Depth";
plantingDepthTextField.borderStyle = UITextBorderStyleLine;
plantingDepthTextField.backgroundColor = [UIColor whiteColor];
plantingDepthTextField.textColor = [UIColor textFieldTextColor];
plantingDepthTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
plantingDepthTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
plantingDepthTextField.layer.borderWidth = 1.0f;
plantingDepthTextField.leftView = paddingView;
plantingDepthTextField.leftViewMode = UITextFieldViewModeAlways;
plantingDepthTextField.delegate = self;
plantingDepthTextField.tag = 0;
[myScrollView addSubview:plantingDepthTextField];
[self.dataSetDictionary setValue:plantingDepthTextField forKey:#"plantingDepthData"];
myRect = CGRectMake(375, ((4 * 40) + 140), 85, 30);
UITextField *plantingDepthUnitTextField = [[UITextField alloc] initWithFrame:myRect];
plantingDepthUnitTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
plantingDepthUnitTextField.placeholder = #"Unit";
plantingDepthUnitTextField.borderStyle = UITextBorderStyleLine;
plantingDepthUnitTextField.backgroundColor = [UIColor whiteColor];
plantingDepthUnitTextField.textColor = [UIColor textFieldTextColor];
plantingDepthUnitTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
plantingDepthUnitTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
plantingDepthUnitTextField.layer.borderWidth = 1.0f;
plantingDepthUnitTextField.leftView = paddingView;
plantingDepthUnitTextField.leftViewMode = UITextFieldViewModeAlways;
plantingDepthUnitTextField.rightView = rightPaddingView;
plantingDepthUnitTextField.rightViewMode = UITextFieldViewModeAlways;
plantingDepthUnitTextField.delegate = self;
plantingDepthUnitTextField.tag = 0;
[myScrollView addSubview:plantingDepthUnitTextField];
[self.dataSetDictionary setValue:plantingDepthUnitTextField forKey:#"plantingDepthUnitData"];
result:
this method works great to add padding to the left side. its almost like the rightPaddingView gets used up in the first text box.... /boggle
You cant add the same UIImageView to two textfields, a UIView can only be in one view at a time, so you should make various instances of your imageview, as many as you want textfields and assign it like that..
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.).
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];
I'm using UINavigationItem's titleView property to set a custom UILabel with my desired font size/color. Here's my code:
self.headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
self.headerLabel.textAlignment = UITextAlignmentCenter;
self.headerLabel.backgroundColor = [UIColor clearColor];
self.headerLabel.font = [UIFont boldSystemFontOfSize:20.0];
self.headerLabel.textColor = [UIColor colorWithRed:0.259 green:0.280 blue:0.312 alpha:1.0];
self.navigationItem.titleView = self.headerLabel;
In the navigation bar I also have a left bar button. The result is: the text isn't properly centered. I've tried setting the x origin of the label, but this has no effect.
In stead of initWithFrame just use init and put [self.headerLabel sizeToFit] after your last line of code.
If you make the headerLabel a subview of the titleView, you can then set headerLabel's frame to control where it goes within the titleView.
The way you are doing it now, you don't have that control. I think the OS chooses the titleView's frame for you based on the space available.
Hope this helps!
I've used custom title labels for my nav bars in every app I have in the app store. I've tested many different ways of doing so and by far the easiest way to use a custom label in a navigation bar is to completely ignore titleView and insert your label directly into navigationController.view.
With this approach, it's easy to have the title label's frame always match the navigationBar's frame -- even if you are using a custom navBar with a non-standard size.
- (void)viewDidLoad {
[self.navigationController.view addSubview:self.titleLabel];
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didRotateFromInterfaceOrientation:
(UIInterfaceOrientation)fromInterfaceOrientation {
[self frameTitleLabel];
}
- (UILabel *) titleLabel {
if (!titleLabel) {
titleLabel = [[UILabel alloc]
initWithFrame:self.navigationController.navigationBar.frame];
titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:18];
titleLabel.text = NSLocalizedString(#"Custom Title", nil);
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
}
return titleLabel;
}
- (void) frameTitleLabel {
self.titleLabel.frame = self.navigationController.navigationBar.frame;
}
The one caveat to this approach is that your title can flow over the top of any buttons you have in the navBar if you aren't careful and set the title to be too long. But, IMO, that is a lot less problematical to deal with than 1) The title not centering correctly when you have a rightBarButton or 2) The title not appearing if you have a leftBarButton.
I have a same problem; I just somehow solved this issue by calculating the title length and set the label frame width accordingly. Although this is not a perfect one but can be manageable. Here is the code.
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.font = [ UIFont fontWithName: #"XXII DIRTY-ARMY" size: 32.0 ];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.0f];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor orangeColor];
//label.text=categoryTitle;
CGFloat verticalOffset = 2;
NSString *reqSysVer = #"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
if (categoryTitle.length > 8)
{
label.frame = CGRectMake(0, 0, 300, 44);
}else {
label.frame = CGRectMake(0, 0, 80, 44);
}
self.navigationItem.titleView = label;
self.navigationItem.title=label.text;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTintColor:[UIColor newBrownLight]];
}
Just calculate exact frame size needed and align to left:
UIFont* font = [UIFont fontWithName:#"Bitsumishi" size:20];
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [title sizeWithFont:font constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeCharacterWrap];
CGRect frame = CGRectMake(0, 0, expectedLabelSize.width, expectedLabelSize.height);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.font = font;
label.textAlignment = UITextAlignmentLeft;
label.text = title;
self.titleView = label;
UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
lbl.text = #"Home";
lbl.textAlignment = UITextAlignmentCenter;
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:20];
lbl.shadowColor = [UIColor blackColor];
lbl.shadowOffset = CGSizeMake(0,1);
self.navigationItem.titleView = vw;
[self.navigationItem.titleView addSubview:lbl];
What worked for me was to update the titleView frame in the viewDidAppear method.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIView *titleView = self.navigationItem.titleView;
CGRect navBarFrame = self.navigationController.navigationBar.frame;
[titleView setFrame:CGRectMake((CGRectGetWidth(navBarFrame) - TitleWidth) / 2, (CGRectGetHeight(navBarFrame) - TitleHeight) / 2, TitleWidth, TitleHeight)];
}