zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

IOS UILabe及UIFont用法总结

ios 总结 用法
2023-09-14 08:59:45 时间

初始化一个UILabel对象,并初始化大小

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100,100)];

设置显示的文字

label.text=@"123";

和字体相关的一个类,字号大小默认17

@property(nonatomic,retain) UIFont*font; 


//7.0之后可用 设置字体风格 //    NSString *const UIFontTextStyleHeadline; 用于标题的风格 //    NSString *const UIFontTextStyleSubheadline;用于副标题的风格 //    NSString *const UIFontTextStyleBody;用于正文的字体 //    NSString *const UIFontTextStyleFootnote;用于脚注的字体 //    NSString *const UIFontTextStyleCaption1;用于标准字幕字体 //    NSString *const UIFontTextStyleCaption2;用于替换字幕字体     label.font=[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; //说实话,没看出什么太大的差别 //设置字体和字体大小 + (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize; //返回所有字体的字体家族名称数组 + (NSArray *)familyNames; //按字体家族名称返回字体名称数组 + (NSArray *)fontNamesForFamilyName:(NSString *)familyName; //设置普通字体字号大小 + (UIFont *)systemFontOfSize:(CGFloat)fontSize; //设置加粗字体字号大小 + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; //设置斜体字号大小 + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; //一些只读属性 //字体家族名称 @property(nonatomic,readonly,retain) NSString *familyName; //字体名称 @property(nonatomic,readonly,retain) NSString *fontName; //字号大小 @property(nonatomic,readonly)        CGFloat   pointSize; //字体设计模型,表示距离最高点偏移余量 @property(nonatomic,readonly)        CGFloat   ascender; //底部的模型偏移量 @property(nonatomic,readonly)        CGFloat   descender; //字体模型的头高信息 @property(nonatomic,readonly)        CGFloat   capHeight; //字体模型的xHeight信息 @property(nonatomic,readonly)        CGFloat   xHeight; //字体行高 @property(nonatomic,readonly)        CGFloat   lineHeight NS_AVAILABLE_IOS(4_0); //模型主体信息 @property(nonatomic,readonly)        CGFloat   leading; //创建一个新字体与当前字体相同,除了指定的大小 - (UIFont *)fontWithSize:(CGFloat)fontSize; //通过描述信息返回字体 7.0后可用 + (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat)pointSize NS_AVAILABLE_IOS(7_0); //返回字体的描述信息,7.0后可用 - (UIFontDescriptor *)fontDescriptor NS_AVAILABLE_IOS(7_0);

使用attributedText绘制

@property(nonatomic,copy)   NSAttributedString *attributedText 

设置高亮的字体颜色

label.highlightedTextColor=[UIColor blueColor];

//设置是否高亮

label.highlighted=YES;

用户交互 默认关闭

label.userInteractionEnabled=NO;

是否有效,默认是YES,无效为灰色

label.enabled=NO;

显示的行数,0为无限

@property(nonatomic) NSInteger numberOfLines;

宽度自适应大小 默认是NO

@property(nonatomic) BOOL adjustsFontSizeToFitWidth;

字符适应宽度:不赞成使用

@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth

最小适应大小2.0-6.0

@property(nonatomic) CGFloat minimumFontSize

最小适应大小 6.0 之后

@property(nonatomic) CGFloat minimumScaleFactor

垂直方向的调整

@property(nonatomic) UIBaselineAdjustment baselineAdjustment;


返回文本绘制矩形

- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;

文本绘制函数

- (void)drawTextInRect:(CGRect)rect

文本自动布局参数

@property(nonatomic) CGFloat preferredMaxLayoutWidth 


30行代码写了个ios叮咚抢菜脚本 大家好,我是Fly哥,好久不见。已经在上海被封太久了, 这段时间一直致力于 两个字 抢菜 , 居委会也不发东西,只能靠抢菜。 但是抢菜有个痛点, 就是 第一你是早起, 5.40 你可能就要起来, 或者 8.20 这个时间段,但是说句实话,臣妾做不到,这样太影响我的工作状态, 每天都提不起劲哇。于是就有了第二种方案 就是在叮咚有运力同时 有菜的时候可以通知我, 然后呢我就可以去抢,不就可以了。 主要是针对ios 用户, 安卓的已经有对应的脚本, 下面就跟着我的步伐一步一步去实现。 安装抓包工具 「stream」 , iOS 直接去应用市场去搜索如图: image-
iOS - autoreleasepool 源码 AutoreleasePool:自动释放池是 Objective-C 开发中的一种自动内存回收管理的机制,为了替代开发人员手动管理内存,实质上是使用编译器在适当的位置插入release、autorelease等内存释放操作。当对象调用 autorelease 方法后会被放到自动释放池中延迟释放时机,当缓存池需要清除dealloc时,会向这些 Autoreleased 对象做 release 释放操作。