You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I called PKHUD show content view as follow, but content view's frame is zero, cannot show on view. How to deal with the frame of contentView without set one? Is it possible to auto layout the content View?
let content = TipMessageView(type: type)
content.label.text = message
PKHUD.sharedHUD.contentView = content
PKHUD.sharedHUD.show()
PKHUD.sharedHUD.hide(afterDelay: TimeInterval(delaySec), completion: { (success) in
if completion != nil {
DispatchQueue.main.async {
completion!()
}
}
})
Code of TipMessageView:
class TipMessageView: UIView {
private var leftView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.clear
return view
}()
private var rightView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.clear
return view
}()
private var icon: UIImageView = {
let view = UIImageView()
view.backgroundColor = UIColor.clear
return view
}()
var label: UILabel = {
let label = UILabel()
label.backgroundColor = UIColor.clear
label.textAlignment = .center
label.font = UIFont.PingFangSC_Semibold(size: 14)
label.textColor = UIColor.white
return label
}()
private var _type: TipMessageType = .success
var type: TipMessageType {
get {
return _type
}
set(newValue) {
_type = newValue
if _type == .success {
self.backgroundColor = UIColor(hexString: "#37B0CD")
self.icon.image = UIImage(named: "tip_hud_suc")
} else if _type == .fail {
self.backgroundColor = UIColor(hexString: "#F26868")
self.icon.image = UIImage(named: "tip_hud_fail")
}
}
}
init(type: TipMessageType) {
//CGRect(x:0, y:0, width:204, height: 56)
super.init(frame: CGRectZero)
self.layer.cornerRadius = 4
self.clipsToBounds = true
self.addSubview(self.leftView)
self.addSubview(self.icon)
self.addSubview(self.label)
self.addSubview(self.rightView)
self.type = type
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
self.leftView.snp.makeConstraints { (make) in
make.left.equalTo(self)
make.centerY.equalTo(self)
make.width.equalTo(self.rightView)
make.height.equalTo(1)
}
self.icon.snp.makeConstraints { (make) in
make.centerY.equalTo(self)
make.left.equalTo(self.leftView.snp.right)
make.width.equalTo(19)
make.height.equalTo(19)
}
self.label.snp.makeConstraints { (make) in
make.centerY.equalTo(self)
make.left.equalTo(self.icon.snp.right).offset(4)
}
self.rightView.snp.makeConstraints { (make) in
make.centerY.equalTo(self)
make.left.equalTo(self.label.snp.right)
make.right.equalTo(self)
}
}
}
The text was updated successfully, but these errors were encountered:
I called PKHUD show content view as follow, but content view's frame is zero, cannot show on view. How to deal with the frame of contentView without set one? Is it possible to auto layout the content View?
Code of TipMessageView:
The text was updated successfully, but these errors were encountered: