I want my navigation bar to show two things in the middle. One them is going to be List name, and the other one will be name of users. User names will be placed under list name. What i have done so far is, i created two label and one superview programatically and set the titleView of navigationItem.
override func viewDidLoad() {
super.viewDidLoad()
var rectForView = CGRect(x: 0, y: 0, width: 190, height: 176)
var viewForTitle = UIView(frame: rectForView)
var rectForNameLabel = CGRect(x: 0, y: 63, width: 190, height: 30)
var listNameLabel = UILabel(frame: rectForNameLabel)
listNameLabel.text = "Name of the List...."
listNameLabel.textAlignment = NSTextAlignment.Center
listNameLabel.font = UIFont(name: "HelveticaNeue-Bold", size: 15)
var rectForListLabel = CGRect(x: 0, y: 93, width: 190, height: 20)
var usersOfListLabel = UILabel(frame: rectForListLabel)
usersOfListLabel.text = "some Users...."
usersOfListLabel.textAlignment = NSTextAlignment.Center
usersOfListLabel.font = UIFont(name: "HelveticaNeue", size: 10)
viewForTitle.addSubview(listNameLabel)
viewForTitle.addSubview(usersOfListLabel)
self.navigationItem.titleView = viewForTitle
The thing is, I'm picking width randomly, which leads to alignment problems in different devices. How to achieve middle alignment in my case?
Aucun commentaire:
Enregistrer un commentaire