边框后的超薄背景颜色线

时间:2017-01-02 16:03:14

标签: ios swift uiview autolayout

我正在制作custom UIView。我有red circle white border view作为class QTBadgedView: UIView { fileprivate lazy var badgeView: UIView = { let badge = UIView() badge.translatesAutoresizingMaskIntoConstraints = false badge.layer.borderColor = UIColor.white.cgColor badge.layer.borderWidth = 2 return badge }() override init(frame: CGRect) { super.init(frame: frame) initialize() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) initialize() } override func layoutSubviews() { super.layoutSubviews() badgeView.layer.cornerRadius = badgeView.frame.width/2 } } extension QTBadgedView { public var badgeColor: UIColor? { get { return badgeView.backgroundColor } set(newColor) { badgeView.backgroundColor = newColor } } } extension QTBadgedView { fileprivate func initialize() { addSubview(iconImageView) addSubview(badgeView) NSLayoutConstraint.activate([ iconImageView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor), iconImageView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor), iconImageView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor), iconImageView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor), badgeView.heightAnchor.constraint(equalToConstant: 50), badgeView.widthAnchor.constraint(equalToConstant: 50), badgeView.topAnchor.constraint(equalTo: iconImageView.topAnchor), badgeView.trailingAnchor.constraint(equalTo: iconImageView.trailingAnchor), ]) } } 的一部分。

我希望它可见,但我在边框周围使用backgroundColor的颜色得到一条很细的线条。

我怎样才能摆脱这条线?

谢谢!

red circle

我的代码:

{{1}}

0 个答案:

没有答案