2016年5月31日 星期二

讓tableCell的分隔線從頭連到尾(iOS 8以後)

//viewDidLoad
tableView.layoutMargins = UIEdgeInsetsZero
tableView.separatorInset = UIEdgeInsetsZero

//setup Cell
cell!.layoutMargins = UIEdgeInsetsZero

2016年5月25日 星期三

UIScrollView裡面的點擊事件反應很慢

var delaysContentTouchesBool

If the value of this property is true, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is false , the scroll view immediately callstouchesShouldBegin:withEvent:inContentView:. The default value is true.

同樣一個UISegmentedControl,加在ScrollView裡面反應就異常的慢,原來是UIScrollView的subview上的touch事件會被延遲,目的是為了確定當次的手勢不是要滑動。
如果你想讓你的scrollView以點擊事件為主:
yourScrollView.delaysContentTouches = false
如果你想讓你的scrollView以滑動事件為主:
yourScrollView.delaysContentTouches = true

2016年5月20日 星期五

讓UIButton的文字title顯示在圖片上

// 因為UIButton預計是將title接在image的右邊,所以要用UIEdgeInsets把title往左移到跟圖片相等的位置。
if let imageWidth = yourButton.imageView?.intrinsicContentSize().width {
        yourButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, 0)

        }

// 其實setImage的作用應該是在Button上的加上小圖示
[[小圖示]按鈕文字]

// 另外一種作法是用setBackgroundImage來作為Button的底圖
button.setBackgroundImage(UIImage(named: "home_button.png"), forState: .Normal)

button.setBackgroundImage(UIImage(named: "home_button_light.png"), forState: .Highlighted)