示例1:文本绘制在标签的底部,几乎在边界之外:
示例2:文本在1行(而不是2)上绘制,并且不进行自动换行,仅尾部截断.
这是我在上面列出的两个iOS版本中使用的代码.
CGSize boundingSize = CGSizeMake(214,9999);CGRect boundingRect = CGRectZero;[self.nameLabel setNumberOflines:2];// for iOS7if([self.place.placename respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]){ NSMu@R_301_5991@ParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mu@R_301_5991@copy]; [paragraphStyle setlineBreakMode:NSlineBreakByWorDWrapPing]; boundingRect = [self.place.placename boundingRectWithSize:boundingSize options:NsstringDrawingUseslineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys: self.nameLabel.Font,NSFontAttributename,paragraphStyle,NSParagraphStyleAttributename,nil] context:nil];}else{ // pre iOS7 CGSize size = [self.place.placename sizeWithFont:self.nameLabel.Font constrainedToSize:boundingSize lineBreakMode:NSlineBreakByWorDWrapPing]; boundingRect = CGRectMake(0,size.wIDth,size.height);}[self.nameLabel setFrame:CGRectMake(CGRectGetMaxX(self.photoImageVIEw.frame)+15,CGRectGetMinY(self.photoImageVIEw.frame),boundingRect.size.wIDth,boundingRect.size.height)];[self.nameLabel setText:[place placename]];
有任何想法吗?提前致谢.
解决方法 我已就此问题与Apple联系,他们已经确认这是iOS 7.0.3的一个错误,已在iOS 7.1.1中修复.总结The workaround for the issue (I used to use) is to create your own UILabel subclass,overrIDe the – (voID)drawTextInRect: method,and use Nsstring’s – (voID)drawInRect:withAttributes: to render the string. (Apple Developer)
以上是内存溢出为你收集整理的在iOS 7.0.3中使用boundingRectWithSize的UILabel渲染问题全部内容,希望文章能够帮你解决在iOS 7.0.3中使用boundingRectWithSize的UILabel渲染问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)