0
我想添加一個「日曆天」的形象環繞,像這樣的一個可點擊的UI按鈕一些文字:調整大小的背景圖像上的UIButton
let button = UIButton()
let X_Offset : CGFloat = (95 * CGFloat(buttonCount)) + 10
let scrollHeight = scrollView.bounds.height
button.frame = CGRect(x: X_Offset, y: scrollHeight/6, width: 70, height: 60)
let buttonText = event.startTime.toShortDayOfWeekString() + "\n" + event.startTime.toShortDayOfMonthString()
button.titleLabel!.lineBreakMode = .byWordWrapping
button.titleLabel!.textAlignment = .center
button.setTitle(buttonText, for: .normal)
button.tag = i
button.backgroundColor = CompanyColor.Red.color
let image = UIImage(named: "calendarDay")
button.setBackgroundImage(image, for: .normal)
button.titleLabel?.font = UIFont(name: "Roboto", size: 14)
button.layer.cornerRadius = 8
button.clipsToBounds = true
,但圖像侵佔文字有點太很多: 如何獲得背景圖片以略微放大併爲文字留出足夠的空白?
嗨Jay,這些似乎對背景圖像沒有任何影響,只是前景之一。 –
好吧!一種你可以移動背景圖像的方法是通過子類「UIButton」,你必須重寫'func backgroundRect(forBounds bounds:CGRect)'。我很確定這會適用於你正在尋找的東西。 – Jay