[英]Swift UILabels in a UIView
我在表视图单元格内有一个UIView。 我想在该表格视图中显示文本。 这是我到目前为止在UIView.swift文件中拥有的内容。
import Foundation
import UIKit
@IBDesignable
class CardView: UIView {
var contact: Contact?
@IBInspectable var cornerRadius: CGFloat = 2
@IBInspectable var shadowOffsetWidth: Int = 0
@IBInspectable var shadowOffsetHeight: Int = 0
@IBOutlet weak private var nameLabel: UILabel!{
self.nameLabel.text = "Name: \(contact!.name)"
}
override func layoutSubviews() {
layer.cornerRadius = cornerRadius
let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius)
layer.masksToBounds = false
layer.cornerRadius = 5.0
layer.shadowColor = UIColor.blackColor().colorWithAlphaComponent(0.2).CGColor
layer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight);
layer.shadowOpacity = 0.8
layer.shadowPath = shadowPath.CGPath
}
}
标签无法生成文本存在错误。 任何帮助都会很棒!
您将需要在设置文本的位置修复代码。
@IBOutlet weak private var nameLabel: UILabel!{
didSet{
nameLabel.text = "Contact name goes here..."
}
}
因此,只要笔尖加载逻辑从情节提要中设置了标签,就会调用didSet中的代码,您可以在其中进行任何设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.