我想在导航中显示红色循环和文本。
self.btnNewUpdates.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
但是这行代码无法正常工作。我将宽度20更改为30或10或任何值,它不会正确更改:
我的代码:
@IBOutlet weak var btnNewUpdates: UIButton!
...
self.btnNewUpdates.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
//self.btnNewUpdates.contentHorizontalAlignment = .right
//btnNewUpdates.contentMode = .scaleAspectFit
self.btnNewUpdates.setImage(UIImage(named:"menuImg"), for: .normal)
self.btnNewUpdates.setTitleColor(UIColor.white, for: .normal)
self.btnNewUpdates.setTitle("1000", for: .normal)
self.btnNewUpdates.titleLabel?.backgroundColor = UIColor.red
self.btnNewUpdates.setNeedsLayout()
self.btnNewUpdates.layoutIfNeeded()
self.btnNewUpdates.titleLabel?.layer.cornerRadius = (self.btnNewUpdates.titleLabel?.frame.width)! / 2.0
self.btnNewUpdates.titleLabel?.layer.masksToBounds = true
self.btnNewUpdates.titleEdgeInsets = UIEdgeInsets(top: -((self.btnNewUpdates.imageView?.frame.width)!-5), left: 0, bottom: 0, right: (self.btnNewUpdates.imageView?.frame.width)!)
self.btnNewUpdates.imageEdgeInsets = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: -(self.btnNewUpdates.titleLabel?.frame.width)!+10)