I have an app in which I have a side menu. In the side menu, the rest of the buttons appear fine but two buttons are stretching weirdly.
screenshot attached.
This is how I am setting button images.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
RearViewTableViewCell *cell = [self.tableViewSideMenu dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell == nil)
{
NSArray *cellView = [[NSBundle mainBundle] loadNibNamed:@"RearViewTableViewCell" owner:nil options:nil];
cell = (RearViewTableViewCell *)[cellView objectAtIndex:0];
cell.btnItemSelector.tag = indexPath.row;
[cell.btnItemSelector setBackgroundImage:[UIImage imageNamed:[buttonUnselect objectAtIndex:indexPath.row]] forState:UIControlStateNormal];
[cell.btnItemSelector setBackgroundImage:[UIImage imageNamed:[buttonSelect objectAtIndex:indexPath.row]] forState:UIControlStateHighlighted];
[cell.btnItemSelector addTarget:self action:@selector(btnMenuItemTapped:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
}
return cell;
}
I am new to adaptive layout. Is it causing issues? On iphone 5s it runs fine but on iphone 6 it is depicting this behaviour. I have added only one constraint (width) to the tableview. The uitableviewcell (custom) i am using here has all the regular constraints of leading space, vertical space, center alignment etc. Any thoughts?
Update: i set the bg color to red and it turns out the two buttons in questions are being resized to much smaller & probably wider view. Why would that happen?
I would recommend you, to use
button.imageinstead ofbutton.backgroundImage. It looks like setting a backgroundImage to aUIButtoncan't handle thecontentModeof your image because it always stretches theUIImageto the same size as theUIButton.If you add the
UIImagejust on thepropertyimageyou can change position of the image inside theUIButtonby changing thecontentEdgeInsetsmanually or inside theInterface Builder.Just in case you want to set an
UIImageas well as aNSStringfor yourUIButton, I would create an own class of typeUIButtonwith anUILabelandUIImageand layout them inside theInterface Builder.