[英]Custom UITableViewCell button title no longer visible after scrolling (reuse)
[英]Custom button title not visible on iPad
我有一個自定義按鈕,其標題在iPhone上可見,但在iPad上不可見。 該小圖標和底部邊框也可見。 按鈕動作確實起作用。 不知道為什么標題沒有顯示在iPad上。 如何調試以找出問題?
我正在模擬器上運行它。
以下是代碼:
import Foundation
import UIKit
class DropDownButton: UIButton {
var bottomBorder = UIView()
enum ImageType: String {
case grey = "Icons/DropDown/Grey"
case white = "Icons/DropDown/White"
case red = "Icons/DropDown/red"
var image: UIImage? { return UIImage(named: rawValue) }
}
var imageType: ImageType = .grey {
didSet{
setImage(imageType.image, for: [])
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
// Setup Bottom-Border
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = .lightGreyColour
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
addSubview(bottomBorder)
bottomBorder.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
bottomBorder.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
bottomBorder.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
bottomBorder.heightAnchor.constraint(equalToConstant: 1).isActive = true // Set Border-Strength
self.sizeToFit()
self.setImage(UIImage(named: "Icons/DropDown/Grey"), for: [])
self.imageEdgeInsets = UIEdgeInsets(top: 0, left: UIScreen.main.bounds.size.width-imageView!.frame.width-16, bottom: 4.0, right: 0)
self.titleEdgeInsets = UIEdgeInsets(top: 0, left: -imageView!.frame.width, bottom: 0, right: imageView!.frame.width)
self.setTitleColor(.white, for: .normal)
self.setTitleColor(.greyColour, for: .disabled)
}
}
class ViewController: UIViewController {
@IBOutlet weak var sortButton: DropDownButton!
override func viewDidLoad() {
super.viewDidLoad()
self.sortButton.setTitleAndColour(title: "Most Recent", titleFont: fontBody!, colour: .white)
self.sortButton.imageType = .white
self.sortButton.bottomBorder.backgroundColor = .white
}
}
似乎iPad上沒有接受限制,附件為屏幕截圖
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.