CoonnozyMof
New Member
I have a few custom buttons set up on the storyboard that I was trying to recreate in code, but somehow I'm not getting the position right in spite of using the same parameters in my CGRectMake function. Another issue is that the autoresizing mask is not working in code in the sense that I have the left, bottom and right strut highlighted so the buttons hold position in both 3.5" and 4" screen size, however my buttons created through code don't do this. I'm posting the XML from my storyboard and then my code to show what exactly I mean. Before the code,a bit of context into what I'm trying to do. I have these custom buttons across multiple controllers/views in my project set up through storyboard.. I"m trying to create a separate controller now with the buttons in the controller programmatically and then have my other controllers inherit from this so that in case I need to make modifications, these will just have to be done once.Here's my code: This is the XML From the storyboard:\[code\]<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="iz0-cT-TPO"> <rect key="frame" x="0.0" y="357" width="106" height="60"/> <autoresizingMask key="autoresizingMask" flexibleMinY="YES"/> <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/> <state key="normal" image="Anotpressed.png"> <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/> <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/> </state> <state key="highlighted" image="Apressed.png"> <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> </state> </button>\[/code\]My equivalent code in my view controller is:\[code\](void)viewDidAppearBOOL)animated{ [super viewDidAppear:animated]; UIButton *AButton=[UIButton buttonWithType:UIButtonTypeCustom]; [AButton setFrame:CGRectMake(0, 357, 106, 60)]; [AButton setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin]; [AButton setImage:[UIImage imageNamed"Anotpressed"] forState:UIControlStateNormal]; [AButton setImage:[UIImage imageNamed"Apressed"] forState:UIControlStateHighlighted]; [AButton setEnabled:YES]; [self.view addSubview:AButton];}\[/code\]At the moment what I'm doing is leaving the storyboard buttons in place and then inheriting from the view controller with the programmatic buttons in order to see if they are the same and I find that my programmatic buttons are much higher than the storyboard buttons even though they have the same co-ordinates etc.I apologize for how verbose this question is, but I wanted to provide a complete picture of what I'm trying to achieve. First of all, how to recreate the same button programmatically and secondly is this (inheritance/subclassing) the correct way to recreate these buttons all across my project?