是ios的新开发者。有没有办法在UILabel上添加一个ImageView?我尝试了这个,但图像隐藏在UILabel :(
var imageTick:UIImage = UIImage(named: "Trash-icon.png")
var imageView:UIImageView = UIImageView(frame: CGRectMake(self.bounds.size.width-50, self.bounds.size.height/2, 30, 30))
imageView.image = imageTick
labelTick.addSubview(imageView)
self.addSubview(labelTick)
答案 0 :(得分:5)
这些对象按照添加到超级视图的顺序堆叠。
不是将labelTick子视图添加到imageView,而是将其添加到图像imageView之前的超级视图中:
var imageTick:UIImage = UIImage(named: "Trash-icon.png")
var imageView:UIImageView = UIImageView(frame: CGRectMake(self.bounds.size.width-50, self.bounds.size.height/2, 30, 30))
imageView.image = imageTick
self.addSubview(labelTick)
self.addSubview(imageView)
或者您也可以使用insertSubview将它们插入superview中的另一个上方或下方: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/insertSubview:aboveSubview: