文本不适合 UILabel Swift

Text not fitting in UILabel Swift

我正在将 json 数据放入 uiwebview(通过故事板添加),如果 json 数据为空,我将添加一个子视图(以编程方式添加)。并在该子视图中我正在添加标签。

当我 运行 时,我可以看到子视图和标签,但它的尺寸很大,所以它超出了子视图。我的代码是

var detailView = UIView(frame: CGRectMake(0, 143, 568, 376)) //Overlapping the UIWebview
//detailView.backgroundColor = UIColor.blackColor()
detailView.contentMode = UIViewContentMode.ScaleAspectFit
detailView.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth
self.view.addSubview(detailView)
var descLabel = UILabel(frame: CGRectMake(0, 0, 200, 200))

descLabel.textColor = UIColor.redColor()
descLabel.font = UIFont(name:"HelveticaNeue;", size: 6.0)
descLabel.text = "No Description was found" +
                        " for \(self.strFullName)" +
                        " please try again later"
descLabel.textAlignment = NSTextAlignment.Center
descLabel.contentMode = UIViewContentMode.ScaleAspectFit
descLabel.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth
detailView.addSubview(descLabel)

当我在模拟器上 运行 它时,我看到 "No Description was fou..." 并且其余部分从屏幕上消失了。从上面的代码可以看出,我尝试设置字体大小,字体大小也没有改变,也尝试把它放在不同的行

我做错了什么导致标签显示成这样?我该如何解决。

提前感谢您提供的任何帮助

解决办法是用descLabel.numberOfLines = 0将标签做成多行,并保证其宽度不大于屏幕宽度。