这是一个类似的问题到这个,但不完全一样.
我创建了一个UITableViewCell的子类,它引用了一个自定义的nib并将其标记为@IBDesignable.在代码和.xib文件中进行的更改在模拟器和设备中正确显示,但不在故事板中显示.
import UIKit
@IBDesignable class TextFieldTableViewCell: UITableViewCell {
var view: UIView!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
func setup() {
view = loadViewFromNib()
view.frame = bounds
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
contentView.addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "TextFieldTableView", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
}
Run Code Online (Sandbox Code Playgroud)
故事板显示永久性的"Designables …
本课程将对直立图像进行透视。
它可以完美运行,但不能在带有 IBDesignable 的 Storyboard 中实时运行。这是非常可悲的。
是否可以使用 CATransform3D 等在带有 IBDesignable 的 Storyboard 上进行实时显示?
// Twist.swift .. twist on Y, perspective from the left
import UIKit
@IBDesignable
class Twist:UIViewController
{
@IBInspectable var perspective:CGFloat = 0.5 // -1 to 1
@IBOutlet var im:UIView! // the image you want to twist on y
override func prepareForInterfaceBuilder()
{ twist(perspective) }
override func viewDidAppear(animated: Bool)
{
twist(perspective)
super.viewWillAppear(animated)
}
func twist(f:CGFloat) // -1 to 1
{
// hinge around left edge
im.layer.anchorPoint = CGPointMake(0, 0.5) …Run Code Online (Sandbox Code Playgroud)