【发布时间】:2017-05-02 09:01:51
【问题描述】:
我有UIScrollView 和UILabel。当用户向上/向下滚动我的 UIScrollView 时,我想将 UILabel 的大小从 33.0 动态更改为 0.0 ,从 0.0 更改为 33。
我该怎么做?
@IBOutlet weak var myLabel : UILabel!
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
let fontpointmath = (myLabel.font.pointSize / (offset / 100) - 15)
if offset > 0 {
if fontpointmath < 0 {
myLabel.font = UIFont(name: "Arial", size: 0.0)
}else if fontpointmath > 33 {
myLabel.font = UIFont(name: "Arial", size: 33.0)
}else{
myLabel.font = UIFont(name: "Arial", size: CGFloat(fontpointmath))
}
}
我当前的代码只允许字体大小为 15 磅左右,并且不会更改为 0。当用户再次向下滚动时,它也不会上升到 33。
【问题讨论】:
标签: ios swift uiscrollview swift3