cocoa-touch:为什么不应用字体?

发布于 2024-11-03 01:42:26 字数 1556 浏览 1 评论 0原文

我正在尝试对 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];

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2024-11-10 01:42:26

设置字体属性时指定了错误的变量名称。您的代码显示: 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 read viewNoteDateWeekDay.font = ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文