2014-09-06 64 views
1

我是ios的新開發者。有沒有一種方法可以在UILabel上添加UIImageView?我試過,但圖像是從的UILabel在UILabel上添加圖片Swift

隱藏:(

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) 

回答

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,將它們插入高於或低於另一個在上海華: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/insertSubview:aboveSubview