I have to manage my UIButton
position at the right side of a UITableViewCell
like an image below.
in this cell I gave all my constraints from storyboard except of button..because I created button at runtime like below
In tableview:cellForRowAtIndexPath
method
let mybutton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
var width:CGFloat = UIScreen.mainScreen().bounds.width
mybutton.frame = CGRectMake(width - 108, 8, 100, 31)
mybutton.tag = indexPath.row
cell?.contentView.addSubview(mybutton)
So the problem is when we launch the app in portrait its ok but when we rotate it, button displays at portrait position...for e.g. if the button position at portrait 220 then in landscape it displays at 220 and after scrolls it looks ok because of cell reusability...
To solve this I'll trying to manually add few constraints to button.I don't know much about how to add constraints programatically but i'll add constraints like below one for top position..and similar with trailing
cell?.contentView.addConstraint(
NSLayoutConstraint(item:imageview ,
attribute: NSLayoutAttribute.Top,
relatedBy: NSLayoutRelation.Equal,
toItem:mybutton ,
attribute:NSLayoutAttribute.Top,
multiplier: 1, constant: 8))
but it displays breaking constraints...
So my questions are...
How to deal with storyboard + manually constraints
How to position button at the right side of a cell