ios - How to set UITextField in UINavigationBar sizeToFit? -
i have been unable find solution issue. unable give uitextfield, textfield
, sizetofit
property when placed in uinavigationbar.
i have tried: textfield.sizetofit()
and of course interface builder doesn't give options when put uinavigationbar. solutions awesome, thank you!
create outlet textfield
, call function in viewdidload
(you paste code below directly in viewdidload
):
func setwidth() { var frame: cgrect = self.textfield.frame frame.size.width = self.view.frame.width self.textfield.frame = frame }
update
change size on rotation add following lines of code:
in viewdidload
add observer:
nsnotificationcenter.defaultcenter().addobserver(self, selector: "rotated", name: uideviceorientationdidchangenotification, object: nil)
add function detect orientation , resize textfield
:
func rotated(){ if(uideviceorientationislandscape(uidevice.currentdevice().orientation)){ print("landscape") setwidth() } if(uideviceorientationisportrait(uidevice.currentdevice().orientation)){ print("portrait") setwidth() } }
Comments
Post a Comment