cocoa-touch:为什么不应用字体?
我正在尝试对 UILabel 的外观进行编码,但无法应用其他字体。有趣(或者相当烦人)的事情是,如果我添加第二个 UILabel,字体将应用于第二个标签,而不是第一个标签。我对此有点疯狂......尤其是如果我尝试的话,字体大小不会改变。
我的代码(在我的 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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置字体属性时指定了错误的变量名称。您的代码显示:
viewNoteTitle.font = ...
当它应该读取viewNoteDateWeekDay.font = ...
You are specifying the wrong variable name when you're setting the font property. Your code says:
viewNoteTitle.font = ...
when it should readviewNoteDateWeekDay.font = ...