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