What is the need to resize subviews programmatically when using storyboards?

不羁的心 提交于 2019-12-11 13:22:29

问题


I am well versed with custom views. Today I have started using storyboards & I am not able to convince myself on the usage of storyboard.

Problem: - I have set up by View Controller in storyboard. - Running on simulator 4 inch, I am good to Go with the layouts of Views. - Running on simulator 3.5 inch, I am upset, as my view is partially visible.

Here are screen shots.

  • My SotryBaord (Look at the "Delete User" Button).

  • Delete User button frame:

  • Running on Simulator 4 inch

  • Running on Simulator 4 inch (I have problem)

how do I get the frame adjusted with layouts so that it runs clear in both size iPhones. My delete user button should not go off the screen.


回答1:


Mate, Auto layout is somewhat complex, you need to master it while giving lot of time, but if you want to finish it in minutes, just uncheck the auto-layout, select every UI element and set its auto-resizing like this

.

You can change the auto-layout differently, and can see the changes by just tapping this button

Hope this will help and save time.




回答2:


Very good question. I had ran into exactly same issues as you have with every single app of mine when I upgraded them to support iphone 5 screen size.

What I ended up doing was disable autolayout but I still use story board to place all my buttons, views, images etc. I make sure that I am using 3.5in in my storyboard while placing all the items. I then connect those UILabel or UIButton etc to an IBoutLet and then in my ViewDidLoad I check to see if its iphone 4 vs iPhone 5 and re position all the buttons accordingly.

for example.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            if(result.height == 480)
            {
                // iPhone Classic

            }
            if(result.height == 568)
            {
                // iPhone 5 this is the offset I am using
                int yInt = 50;

                [blurSlider setFrame:CGRectMake(31, 406+yInt, 271, 34)];
                [alphaSlider setFrame:CGRectMake(31, 447+yInt, 271, 34)];

                [blurLabel setFrame:CGRectMake(33, 392+yInt, 71, 24)];
                [alphaLabel setFrame:CGRectMake(33, 436+yInt, 71, 24)];
            }
        }
}

Could I have done all the coding without ever using story board? of course I could have but I find the visual aspect of story board appealing and seeing exactly where everything fits on the screen.



来源:https://stackoverflow.com/questions/22021077/what-is-the-need-to-resize-subviews-programmatically-when-using-storyboards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!