Search code examples
iosobjective-ciphoneuitableviewautoresizingmask

objective-c Align UILabe to right inside UitableViewCell using AutoResizingMask


I am creating an iPhone app, now i am trying to align a uilabel inside custom tableview cell to the right using autoresizing mask, i am doing it in interface builder and i am using storyboards, but the problem i am having is that the label just disappears when i run app in iphone 6 simulator, the autoresizing is working fine when i align label to the left of table view cell, but strangely it is not working when i try to align the label right of table view cell, how should i do this?

Note: i don't need to align the uilabel text but need to align the uilabel itself to right.


Solution

  • the answer is used for my project , please customize the x, y , width and height as you need

    I also face the same problem , SO i follow this method cellForRowAtIndexPath

    cell.yourlableName.frame=CGRectMake(add your label x - position,add your label Y position, [[UIScreen mainScreen] bounds].size.width- add your label width, add your label Height ); for example in your iPhone 4 width is 320 so reduce the width 320-yourlabel width, 
    

    else part call this line in your custom cell class

    - (void)awakeFromNib {
    
         cell.yourlableName.frame=CGRectMake(180.0f,220.0f, [[UIScreen mainScreen] bounds].size.width-216.0f, 19.0f); 
    
       }
    

    its working fine for me in all device it shows in right side perfectly.