基于页面的应用程序中的换行符

时间:2013-01-07 05:17:34

标签: iphone ios6 uilabel

在我的基于页面的应用程序中,我想在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);

但是没有显示出任何差异?我的代码有什么问题?

1 个答案:

答案 0 :(得分:2)

尝试此行也可以在代码和代码中添加这些行。检查:

textstring.lineBreakMode = UILineBreakModeWordWrap;

titlestringcop.lineBreakMode = UILineBreakModeWordWrap;