drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning 和动态获取label的高度
来源:互联网 发布:java 定义泛型返回值 编辑:程序博客网 时间:2024/06/05 12:02
NSString *font = @"Courier-Bold"; #ifdef __IPHONE_7_0 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; paragraphStyle.alignment = NSTextAlignmentCenter; [textToDraw drawInRect:renderingRect withAttributes: @{NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle }]; #else [textToDraw drawInRect:renderingRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter]; #endif
这里定义NSMutableParagraphStyle类型来添加需要的参数。
- (CGSize)sizeOfTextForCurrentSettings
{
return [self.badgeText sizeWithAttributes:@{NSFontAttributeName:self.badgeTextFont}];
//return [self.badgeText sizeWithFont:self.badgeTextFont];
}
CGRect textFrame = rectToDraw;
CGSize textSize = [self sizeOfTextForCurrentSettings];
textFrame.size.height = textSize.height;
textFrame.origin.y = rectToDraw.origin.y + ceilf((rectToDraw.size.height - textFrame.size.height) / 2.0f);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
paragraphStyle.alignment = NSTextAlignmentCenter;
[self.badgeText drawInRect:textFrame withAttributes:@{NSFontAttributeName:self.badgeTextFont,
NSParagraphStyleAttributeName:paragraphStyle}];
动态获取label高度,前提是定义的时候高度为0
- (CGFloat)lableFinalHeightWithText:(NSString *)labelText {
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:self.font forKey: NSFontAttributeName];
CGRect endLabelFrame = self.frame;
endLabelFrame.size = [labelText boundingRectWithSize:CGSizeMake(self.frame.size.width, CGFLOAT_MAX)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:stringAttributes context:nil].size;
return endLabelFrame.size.height;
}
- drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning 和动态获取label的高度
- drawInRect: withFont: lineBreakMode:弃用
- iOS中如何动态获取label的宽度和高度
- iOS 获取label的动态高度
- 动态的获取label文本的宽度和高度,来判断是不是需要折行显示
- Warning: $HADOOP_HOME is deprecated.
- Warning: $HADOOP_HOME is deprecated.
- 动态设置label的高度
- 动态适应label的高度
- iOS 获取label的text的宽度和高度
- Warning: $HADOOP_HOME is deprecated. 关闭
- Warning:$HADOOP_HOME is deprecated问题
- Warning: $HADOOP_HOME is deprecated. hadoop
- Warning: $HADOOP_HOME is deprecated解决方法
- Warning: Using innodb_additional_mem_pool_size is DEPRECATED
- Warning: $HADOOP_HOME is deprecated.的原因以及解决方法。
- Hadoop启动时出现 Warning HADOOP_HOME is deprecated 的解决方案
- hadoop1.2.1报Warning: $HADOOP_HOME is deprecated. 的解决方法
- [iOS]#Swift#可选解析-optional
- JAVA_SE系列:18.比较运算符、逻辑运算符、三目运算符
- Android android:windowSoftInputMode 属性整理
- Android Studio上Git使用指南
- 关于conversion from string to type date is not valid错误
- drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning 和动态获取label的高度
- C++
- GTK+浅谈之二信号回调和事件
- [案例讲解]拆解完整案例 领悟云表神奇(前言)
- How to Delete From or Add Resource to OCR in Oracle Clusterware (文档 ID 1069369.1)
- Servlet中的过滤器Filter详解
- sql 函数记录
- Combinations
- hdu 1237 简单计算器(数组模拟栈,队列)