leading:行间距(一般为0) let lb = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 100)) let font = UIFont.systemFont 14.091796875 print("xHeight: \(font.xHeight)") // 10.439453125 print("leading: \(font.leading)") // 0.0 参考: UIFont 属性对应 iOS 对UIFont的新的理解
CGRectMake(100, 100, 100, 100)]; 设置显示的文字 label.text=@"123"; 和字体相关的一个类,字号大小默认17 @property(nonatomic,retain) UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; //说实话,没看出什么太大的差别 //设置字体和字体大小 + (UIFont *)fontWithName *)systemFontOfSize:(CGFloat)fontSize; //设置加粗字体字号大小 + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize ; //设置斜体字号大小 + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; //一些只读属性 //字体家族名称 @property(nonatomic *)fontWithSize:(CGFloat)fontSize; //通过描述信息返回字体 7.0后可用 + (UIFont *)fontWithDescriptor:(UIFontDescriptor
增加了 3 种新的宽度样式:compressed、condensed与expanded,加上默认的standard,目前 UIFont 共有 4 种字体宽度。 YungFan import UIKit class ViewController: UIViewController { // 定义4种宽度不同的字体 let expanded = UIFont.systemFont (ofSize: 27, weight: .bold, width: .expanded) let standard = UIFont.systemFont(ofSize: 27, weight : .bold, width: .standard) let condensed = UIFont.systemFont(ofSize: 27, weight: .bold, width: .condensed ) let compressed = UIFont.systemFont(ofSize: 27, weight: .bold, width: .compressed) lazy var
UIFont.TextStyle 增加了新的超大字体样式extraLargeTitle与extraLargeTitle2。 view.addSubview(label1) view.addSubview(label2) view.addSubview(label3) } } UIFont.TextStyle
Compressed Condensed Expend UIFont.Width Apple 引入了新的结构体 UIFont.Width,这代表了一种新的宽度样式。 目前已有的四种样式。 SF 字体和新的宽度样式 如何将 SF 字体和新的宽度样式一起使用 为了使用新的宽度样式,Apple 有一个新的 UIFont 的类方法来接收新的 UIFont.Width 。 : UIFont.Weight, width: UIFont.Width ) -> UIFont } 你可以像平常创建字体那样来使用新的方法。 将 UIfont 转为 Font 我们从 在 SwiftUI 中如何将 UIFont 转换为 Font[1] 中了解到,Font 有初始化方法可以接收 UIFont 作为参数。 步骤如下 你需要创建一个带有新宽度样式的 UIFont。 使用该 UIFont 创建一个 Font 。 然后像普通 Font 一样使用它们。
这时实际上我们已经将字体添加进了工程中,但是在在使用这个字体时,字体的名字有时和文件名是不一样的,我们需要知道真实的字体名称,通常情况下,我们会讲所有字体名称打印出来: for (NSString * name in [UIFont familyNames]) { for (NSString * fo in [UIFont fontNamesForFamilyName:name]) { NSLog (@"%@",fo); } } 5、找到我们需要的字体,如下使用即可: UIFont * font = [UIFont fontWithName:@"yuweij" size: rootDic = [NSDictionary dictionaryWithContentsOfFile:paths]; //遍历当前所有字体 for (NSString * name in [UIFont NSArray * fontArray = [rootDic objectForKey:name]; BOOL tip = NO; for (NSString * fo in [UIFont
OC // textView.font = [UIFont systemFontOfSize:17]; // textView.text = @"请�写在自定义属性前面,如果长度大于limitLength = [UIColor redColor]; textView.limitPlaceColor = [UIColor redColor]; textView.placeholdFont = [UIFont systemFontOfSize:17]; textView.limitPlaceFont = [UIFont systemFontOfSize:17]; // textView.limitLines textview.placeholdColor = .red textview.limitLabelColor = .red textview.placeholdFont = UIFont.boldSystemFont (ofSize: 17) textview.limitLabelFont = UIFont.boldSystemFont(ofSize: 17) // textview.limitLines
NSInteger count; @property (assign, nonatomic) NSTimeInterval lastTime; @property (strong, nonatomic) UIFont *font; @property (strong, nonatomic) UIFont *subFont; @end @implementation FPSDisplay + (instancetype NO; self.displayLabel.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.700]; _font = [UIFont fontWithName:@"Menlo" size:14]; if (_font) { _subFont = [UIFont fontWithName:@"Menlo" size :4]; } else { _font = [UIFont fontWithName:@"Courier" size:14]; _subFont = [UIFont
fontSize:(CGFloat)fontSize rectSize:(CGSize)rectSize { UIFont *font = [UIFont systemFontOfSize: fontSize]; CGSize size = [self getStringRectWith:string lineSpacing getStringRectWith:(NSString *)string lineSpacing:(CGFloat)lineSpacing font:(UIFont getStringRectWith:(NSString *)string lineSpacing:(CGFloat)lineSpacing font:(UIFont fontSize: 文字大小 -- 默认为不加粗 func getBoundingFontHeight(rectWidth: CGFloat = CGFloat(MAXFLOAT), font: UIFont
改变 button 的长度 * * @param text */ - (void)setMutableTitleWithString:(NSString *)text textFont:(UIFont implementation UIButton (MutableTitle) - (void)setMutableTitleWithString:(NSString *)text textFont:(UIFont param text * @param font * * @return size */ - (CGSize)sizeForNoticeTitle:(NSString*)text font:(UIFont button setMutableTitleWithString:@"qwertyudfghjkl;iadsdajshdashdasdlshdertyudiertyudfghjkl;io" textFont:[UIFont
instancetype)MCInit { id __self = [self MCInit]; if (self) { // 需要改变字体的大小,和一些其他的设置 self.font= [UIFont { id __self = [self MCInitWithFrame:rect]; if (self) { // 需要改变字体的大小,和一些其他的设置 self.font= [UIFont void)MCAwakeFromNib{ [self MCAwakeFromNib]; if (self) { // 需要改变字体的大小,和一些其他的设置 self.font= [UIFont 10]; self.backgroundColor = [UIColor blueColor]; } } 修改字体(在设置的字体上+n号) - (void)setconanFont:(UIFont *)font { NSLog(@"调用了"); [self setconanFont:[UIFont systemFontOfSize:font.pointSize + 10]]; }
通过UIFont(name:size:)方法使用自定义字体。 let label = UILabel(frame: CGRect(x: 20, y: 200, width: 300, height: 30)) label.font = UIFont nomalLabel) view.addSubview(customLabel) } } 查看注册的字体 // 查看所有已注册的字体(包括系统字体) for family in UIFont.familyNames.sorted () { let names = UIFont.fontNames(forFamilyName: family) print(family, names) }
labelStr.text = @"iOS 在UILabel显示不同的字体和颜色"; labelStr.textColor = [UIColor lightGrayColor]; labelStr.font = [UIFont blueColor] range:NSMakeRange(0, 4)]; // 设置指定区域字体样式和大小 [newStr addAttribute:NSFontAttributeName value:[UIFont textColor = [UIColor lightGrayColor]; label3.backgroundColor = [UIColor yellowColor]; label3.font = [UIFont label3]; label3.text = layoutStr; // 获取这段文字的宽和高 CGSize size = [self SizeOfText:layoutStr withFont:[UIFont ]; [self.view addSubview:imageView]; } // 获取这段文字的宽和高 -(CGSize)SizeOfText:(NSString *)text withFont:(UIFont
iOS文本布局探讨之二——关于TextKit框架中的字体描述 一、引言 UIFont是iOS开发中处理文本字体的类,关于UIFont的相关内容,以前的一篇博客有详细介绍,本片博客主要介绍关于动态字体的应用与字体描述类 UIFont应用介绍:http://my.oschina.net/u/2340880/blog/397115。 类中的如下方法可以创建动态字体: //创建动态字体的字体描述类实例 + (UIFontDescriptor *)preferredFontDescriptorWithTextStyle:(NSString *)style; UIFont 类中的如下方法可以将字体描述类转换成UIFont字体: + (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat systemFontOfSize:14].fontName matrix:transfom]; UIFont * font = [UIFont fontWithDescriptor:fontDes
步骤4: 我可以采用代码的方式输出所有的字体,然后再在里边找新增的是哪一个 // let fontName = UIFont(name: "SF Pro Rounded", size: 17 ) for fontFamilyName in UIFont.familyNames { print("+++++++ : \(fontFamilyName )") for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) { print 步骤5: 使用字体: let fontName = UIFont(name: "SFProRounded-Bold", size: 17) 到此,新的字体库导入和使用完成 参考文档:https://www.it610
new]; labelOrigin.frame = CGRectMake(15, 50, self.view.frame.size.width-15, 50); labelOrigin.font = [UIFont label = [UILabel new] .func_frame(CGRectMake(15, 50, self.view.frame.size.width-30, 50)) .func_font([UIFont buttonOrigin.bounds; [buttonOrigin.layer addSublayer:gradientLayer]; buttonOrigin.titleLabel.font = [UIFont self.view.frame.size.width-15, 50)) .func_gradientHorizontalColor(UIColor.redColor,UIColor.blueColor) .func_font([UIFont
fillCharacterCount, rankStr.length)]; [textAttributedString addAttribute:NSFontAttributeName value:[UIFont NSMakeRange(0, fillCharacterCount)]; [textAttributedString addAttribute:NSFontAttributeName value:[UIFont fillCharacterCount, rankStr.length)]; [textAttributedString addAttribute:NSFontAttributeName value:[UIFont NSMakeRange(0, fillCharacterCount)]; [textAttributedString addAttribute:NSFontAttributeName value:[UIFont
//设置文字的行数 设为0->会自动换行 text_label.numberOfLines = 0; CGFloat textH = [text sizeWithFont:[UIFont 0; //设置内部文字的字体属性 NSDictionary *attr = @{ NSFontAttributeName : [UIFont context:nil].size.height; 计算一句文字的宽度 //设置内部文字的字体属性 NSDictionary *attr = @{NSFontAttributeName:[UIFont
/// @return 返回自适应的最合适尺寸 CGSize calcTextSize(CGSize fitsSize, id text, NSInteger numberOfLines, UIFont if (font == nil) { font = [UIFont systemFontOfSize:17]; } CGFloat systemVersion ; } //上述方法的精简版本 NS_INLINE CGSize calcTextSizeV2(CGSize fitsSize, id text, NSInteger numberOfLines, UIFont paragraphStyle1.headIndent = rand() % 10; paragraphStyle1.tailIndent = rand() % 10; UIFont *font1 = [UIFont systemFontOfSize:rand() % 20 + 3.0]; NSRange range2 = NSMakeRange(
MOTitleLineViewType)type normalColor:(UIColor *) normalColor selectedColor:(UIColor *)selectedColor font:(UIFont MOTitleLineViewType)type normalColor:(UIColor *) normalColor selectedColor:(UIColor *)selectedColor font:(UIFont UIColor *normalColor; @property(nonatomic, strong) UIColor *selectedColor; @property(nonatomic, strong) UIFont MOTitleLineViewType)type normalColor:(UIColor *)normalColor selectedColor:(UIColor *)selectedColor font:(UIFont MOTitleLineViewType)type normalColor:(UIColor *)normalColor selectedColor:(UIColor *)selectedColor font:(UIFont