标签: uifont

UITextView字体为零

我在故事板中创建了一个字体大小为14的UITextView,并将其连接到我的ViewController的detailDescriptionLabel属性.此代码位于viewDidLoad中:

self.detailDescriptionLabel.font=[UIFont systemFontOfSize:10];
NSLog(@"text is %@; font is %@", self.detailDescriptionLabel.text, self.detailDescriptionLabel.font);
Run Code Online (Sandbox Code Playgroud)

控制台输出如下:

text is Lorem Ipsum; font is (null)
Run Code Online (Sandbox Code Playgroud)

为什么字体设置为nil?setFont:正在工作; 字体缩小了.我希望得到字体,所以在手势后我可以在字体上调用lineHeight.这样,我可以使用以下代码找出已经使用了哪一行:

int line = [tap locationInView:tap.view].y / self.detailDescriptionLabel.font.lineHeight;
Run Code Online (Sandbox Code Playgroud)

这里的字体也是零.line设置为-2147483648,这显然不是我想要的.

fonts objective-c uitextview uifont ios

34
推荐指数
2
解决办法
7202
查看次数

如何从iOS设置中检测动态字体大小更改?

在设置内部 - >常规 - >文本大小,更改文本大小后,我必须退出自己的应用程序才能应用大小

 [UIFont preferredFontForTextStyle:..]
Run Code Online (Sandbox Code Playgroud)

是否有代表或通知通知我的应用重新应用新尺寸?

更新:我尝试了以下但有趣的是,字体大小将在我BG之后应用并启动应用程序TWICE.

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fromBg:) name:UIApplicationDidBecomeActiveNotification object:nil];

}


 -(void) fromBg:(NSNotification *)noti{

    self.headline1.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
    self.subHeadline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
    self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    self.footnote.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
    self.caption1.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
    self.caption2.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2];
//    [self.view layoutIfNeeded];

}
Run Code Online (Sandbox Code Playgroud)

uifont ios

33
推荐指数
2
解决办法
1万
查看次数

如何创建粗体UIFont

我在tableview中做了一些自动换行,因为有些值很大,它们离开了屏幕的边缘.

但是,字体和大小与粗体不匹配表视图的默认设置,并希望有人可以帮我解决这个问题.

这就是我要设置的字段:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText = @"Go get some text for your cell.";
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 20;
}
Run Code Online (Sandbox Code Playgroud)

uitableview uifont ios

31
推荐指数
4
解决办法
5万
查看次数

UIFont fontWithName返回nil

在我的info.plist中,我添加了一个键"应用程序提供的字体"并添加了 EdwardianScriptITCStd.otf 在此输入图像描述

但是,当我尝试获取该字体时,它返回nil:

NSLog(@"%@", [UIFont fontWithName:@"EdwardianScriptITCStd" 
                                size:16.0f]);
Run Code Online (Sandbox Code Playgroud)

我打印了使用的字体系列[UIFont familyNames],它也不存在:

(
    Thonburi,
    "Snell Roundhand",
    "Academy Engraved LET",
    "Marker Felt",
    "Geeza Pro",
    "Arial Rounded MT Bold",
    "Trebuchet MS",
    Arial,
    Marion,
    "Gurmukhi MN",
    "Malayalam Sangam MN",
    "Bradley Hand",
    "Kannada Sangam MN",
    "Bodoni 72 Oldstyle",
    Cochin,
    "Sinhala Sangam MN",
    "Hiragino Kaku Gothic ProN",
    Papyrus,
    Verdana,
    "Zapf Dingbats",
    Courier,
    "Hoefler Text",
    "Euphemia UCAS",
    Helvetica,
    "Hiragino Mincho ProN",
    "Bodoni Ornaments",
    "Apple Color Emoji",
    Optima,
    "Gujarati Sangam MN",
    "Devanagari Sangam MN",
    "Times New Roman",
    Kailasa, …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c uifont ios

28
推荐指数
2
解决办法
2万
查看次数

如何在iOS 9上的UILabel中获取等宽数字

在WWDC 2015上,有一个关于 iOS 9中新"旧金山"系统字体的会话.默认情况下,当与iOS 9 SDK链接时,它使用比例数字渲染而不是等宽数字.在NSFont上有一个方便的初始化程序NSFont.monospacedDigitsSystemFontOfSize(mySize weight:),可用于显式启用等宽数字显示.

但是,我无法找到UIKit相应的UIFont.

uilabel uifont monospace ios ios9

28
推荐指数
4
解决办法
1万
查看次数

Swift 3错误:[_SwiftValue pointSize]无法识别的选择器发送到实例

我刚刚将项目迁移到swift 3并因为一个问题看到了很多崩溃:

终止应用程序由于未捕获的异常"NSInvalidArgumentException",原因是:" - [_ SwiftValue的pointsize]:无法识别的选择发送到实例

出现这种错误的原因是:

[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:]
Run Code Online (Sandbox Code Playgroud)

我注意到的是,如果我将String转换为NSString并调用boundingRectWithSize它,它将抛出该错误.它似乎也发生在许多其他部分,例如,如果我在故事板中发送了一个视图控制器标题,它会抛出相同的错误.

谁有同样的问题?

重现问题:

在Xcode 8中创建一个新的Swift 3项目,并在viewDidLoad中添加以下行:

let attributes: [String: AnyObject?] = [
            NSFontAttributeName: UIFont.systemFont(ofSize: 14)
        ]
    let boundingRect = ("hello" as NSString).boundingRect(with: CGSize(width: 100, height: 100), options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
Run Code Online (Sandbox Code Playgroud)

但正如我所说,它在许多其他地方崩溃,因为UIKit似乎在很多部分内部使用这种方法

string nsstring uifont ios swift

28
推荐指数
1
解决办法
1万
查看次数

从 SwiftUI.Font 转换为 UIFont

我有一个UIViewRepresentableUITextView我想UITextView使用FontSwiftUI 环境中的当前设置字体。我只需要一个简单的初始化,如:

UIFont(_ swiftUIFont: Font)
Run Code Online (Sandbox Code Playgroud)

但我找不到任何这样的东西。而且该Font类型似乎没有任何我可以用来尝试实现一个的信息。有人知道在两种字体表示之间进行转换的方法吗?

fonts uifont swiftui

28
推荐指数
3
解决办法
6677
查看次数

iOS:UIButton titleLabel - 它做了什么吗?

我想制作一个类型为UIButtonTypeCustom的UIButton(用于形状).我想使用button.titleLabel分配标题,因为我需要指定字体.以下代码看起来应该可以工作,但不会 - 没有标签显示,句点.

UIImage *editButtonImage = [UIImage imageNamed: @"editButton.png"];
float width = editButtonImage.size.width;
float height = editButtonImage.size.height;

UIButton *editButton = [UIButton buttonWithType: UIButtonTypeCustom];
editButton.frame = CGRectMake(0, 0, width, height);
[editButton setBackgroundImage: editButtonImage forState: UIControlStateNormal];
editButton.adjustsImageWhenHighlighted = YES;
editButton.titleLabel.text = @"Edit";
editButton.titleLabel.textColor = [UIColor whiteColor];
editButton.titleLabel.textAlignment = UITextAlignmentCenter;
editButton.titleLabel.font = [UIFont fontWithName: @"Helvetica" size: 14];
[self.view addSubview: editButton];
Run Code Online (Sandbox Code Playgroud)

每个人总是说使用setTitle:forState:但是这会给你一个我不喜欢的字体.不推荐使用titleLabel方法 - 它应该可以工作.

我之前已经遇到过好几次并且总是只是解决它,但我真的想弄明白.有任何想法吗?

iphone uibutton uilabel uifont ios

27
推荐指数
1
解决办法
4万
查看次数

27
推荐指数
4
解决办法
3万
查看次数

如何将自定义字体添加到Cocoapod?

我想在Cocoapod中使用自定义字体,但在静态库中使用自定义字体时找不到任何内容.由于没有info.plist文件,因此无法告诉应用程序使用什么字体.

有任何想法吗?

iphone uifont ios cocoapods

25
推荐指数
4
解决办法
3994
查看次数