在我的基于页面的应用程序中,我想在uilabel中使用换行符,我尝试使用以下编码,
@"The farmer and his wife were entranced with joy and danced cheerfully because of their goose lays \n a golden egg",
self.titlestring.frame = CGRectMake(53, 620, 0, 37);
self.titlestringcop.frame = CGRectMake(53, 620, 918, 37);
[self fadein];
[self.titlestring setText:self.dataobject1];
[self.titlestringcop setText:self.dataobject1];
textstring.numberOfLines = 0;
titlestringcop.numberOfLines = 0;
CGSize labelSize = [textstring.text sizeWithFont:textstring.font
constrainedToSize:textstring.frame.size
lineBreakMode:textstring.lineBreakMode];
CGSize labelSize1 = [titlestringcop.text sizeWithFont:titlestringcop.font
constrainedToSize:titlestringcop.frame.size
lineBreakMode:titlestringcop.lineBreakMode];
textstring.frame = CGRectMake(
textstring.frame.origin.x, textstring.frame.origin.y,
textstring.frame.size.width, labelSize.height);
titlestringcop.frame = CGRectMake(
titlestringcop.frame.origin.x, titlestringcop.frame.origin.y,
titlestringcop.frame.size.width, labelSize1.height);
但是没有显示出任何差异?我的代码有什么问题?
答案 0 :(得分:2)
尝试此行也可以在代码和代码中添加这些行。检查:
textstring.lineBreakMode = UILineBreakModeWordWrap;
titlestringcop.lineBreakMode = UILineBreakModeWordWrap;