还有图片顶到状态栏了,设置headerView的frame.y = 64 ,没起作用
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
setUpHeaderView()
setUpAdScrollView()
}
//MARK : 表头视图
func setUpHeaderView() {
let headView = UIImageView()
headView.frame = CGRect(x: 0, y: 64, width: self.view.frame.width, height:250)
headView.backgroundColor = UIColor.lightGrayColor()
self.tableView.tableHeaderView = headView
}
func setUpAdScrollView() {
let adSCView = UIScrollView()
adSCView.delegate = self
adSCView.frame = (self.tableView.tableHeaderView?.frame)!
adSCView.contentSize = CGSize(width: 3 * adSCView.frame.width,height: adSCView.frame.height)
/** 添加轮播图片 */
//创建图片按钮
for i in 0 ..< 3 {
let adBtn = UIButton()
adBtn.frame = CGRect(x: CGFloat(Float(i)) * adSCView.frame.width,y: 0,width: adSCView.frame.width,height: adSCView.frame.height - 20)
adBtn.setImage(UIImage(named: String(format: "ad0%d",i + 1)), forState: UIControlState.Normal)
adSCView.addSubview(adBtn)
}
/** 补充设置 */
adSCView.backgroundColor = UIColor.yellowColor()
//边缘不弹跳 整页滚动 不出现水平提示
adSCView.bounces = false
adSCView.pagingEnabled = true
adSCView.showsHorizontalScrollIndicator = true
adSCView.showsVerticalScrollIndicator = true
self.tableView.tableHeaderView?.addSubview(adSCView)
}
}
百度云连接 http://pan.baidu.com/s/1gf37EEn
headerView
anda ialahUIImageView
, yang mematikan acara klik secara lalai: