Search code examples
iosobjective-cuiscrollviewautoresizingmask

Fix a UIView at the bottom of the screen without Auto-layout


In my app, there is a UITabController that has 3 tabs. They all have a search button that should stay at the bottom of the screen. The 3rd Tab has a UIScrollView and the button must ignore the scroll(the button must be anchored to the bottom of the screen and should be unaffected by scroll). I cannot use auto layout in the app(MUST do this with auto resizing). I have tried all possible combinations with struts and springs and yet the search button stays somewhere in the middle of these screen(Only an issue with the tab that has UIScrollView). Am I missing something? Do methods differ, when handling UIScroll View?


Solution

  • Try this

    #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
    #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
    

    By using this SCREEN_WIDTH and SCREEN_HEIGHT you can set your view to bottom of your screen.

    You can set button frame as

    x = 0
    Y = SCREEN_HEIGHT - 46
    Width = SCREEN_WIDTH
    Height = 46
    

    So that button will stay at bottom.

    Hope it helps.