我知道如何在iOS 7中为按钮添加边框,使用以下代码:
[[myButton layer] setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[[myButton layer] setBorderWidth:1];
[[myButton layer] setCornerRadius:15];
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能添加一个边框?我想只添加顶部边框.
我想用Code中的自定义标头创建UICollectionView。因此,我创建了UICollectionViewCell的子类来描述我的自定义标头。我想在标题的水平线上显示五个标签。因此,我创建了五个标签并将其添加到stackView中。stackview显示我的标签被均等填充。到目前为止,一切都很完美。
标签1标签2标签3标签4标签5
//Label 1
let votesLabel: UILabel = {
let label = UILabel()
let attributedText = NSMutableAttributedString(string: "Votes", attributes: [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 12) ])
attributedText.append(NSAttributedString(string: "\n 0", attributes: [NSForegroundColorAttributeName: UIColor.lightGray, NSFontAttributeName: UIFont.systemFont(ofSize: 14)]))
label.attributedText = attributedText
// label.text = "11\nvotes"
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
// label 2 ... 5
// creating the subview and add the labels to my subview
addSubview(topDividerView)
let stackView = UIStackView(arrangedSubviews: [ votesLabel, and the other 4 labels])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis …Run Code Online (Sandbox Code Playgroud)