2017-03-03 144 views
0

我在我的UIImageView的绘制方法中设置了一些属性。但是,这些似乎没有任何影响。我看不到任何圆角,并且没有掩蔽效果。该视图如下:为绘制UIImageView设置圆角半径

// 
// RoundImage.swift 
// 
// 

import UIKit 

class RoundImage: UIImageView { 

    //------------------ 
    //MARK: - Setup and Initialization 
    //------------------ 

    override init(frame: CGRect) { 
     super.init(frame: frame) 

     self.initialize() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 

     self.initialize() 
    } 

    override func draw(_ rect: CGRect) { 
     super.draw(rect) 

     self.layer.cornerRadius = 30 
     self.layer.masksToBounds = true 
     self.clipsToBounds = true 
    } 

    //Setups content, styles, and defaults for the view 
    private func initialize(){ 
     self.initStyle() 
    } 

    //Sets static content for the view 
    private func staticContent() { 

    } 

    //Styles the view's colors, borders, etc at initialization 
    private func initStyle(){ 


    } 

    //Styles the view for variables that must be set at runtime 
    private func runtimeStyle(){ 

     //TODO: These values cannot be changed in interface builder, but they should be able to be 

    } 

    //------------------ 
    //MARK: - Interface Builder Methods 
    //------------------ 

    //Sets the view up for interface builder with runtime styling and temp display values 
    override func prepareForInterfaceBuilder() { 
     self.runtimeStyle() 
     self.staticContent() 
    } 

    //------------------ 
    //MARK: - Lifecycle Methods 
    //------------------ 

    //Sets the view up with runtime styling and values 
    override func awakeFromNib() { 
     super.awakeFromNib() 

     self.runtimeStyle() 
      self.staticContent() 
     } 


    } 
+1

可能是愚蠢的事情要问,但如果你使用这个在故事板一个UIImageView,你一定要设置类?如果你已经这样做了,在'draw'函数中添加一个断点并检查它是否在那里断开。 –

+0

@PratikPatel是的,我设置了类。奇怪的是,它并没有在我的绘画方法中达到我的断点。 – steventnorris

回答