Q: UIView autoresizingMask bug when setting different fixed left and right margins and flexible width? I'm trying to create a view with a separator that has left inset (like table view cells in iOS 7) using that code:
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 500.0f, 90.0f)];
container.backgroundColor = [UIColor whiteColor];
container.autoresizingMask = UIViewAutoresizingFlexibleWidth;
container.layer.cornerRadius = 5.0f;
container.layer.borderColor = grayColor.CGColor;
container.layer.borderWidth = 1.0f;
NSLog(@"container: %@", NSStringFromCGRect(container.bounds));

UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(13.0f, floorf(container.height / 2), container.width - 13.0f, 1.0f)];
separator.backgroundColor = grayColor;
separator.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[container addSubview:separator];
NSLog(@"separator: %@", NSStringFromCGRect(separator.frame));

As you can see, I explicitly set width of container to 500px. However, later it changes to 258px. And what I get as a result is that:

What should I do to get rid of the redundant right part of the separator? My autoresizingMask seems and looks right when the width of container if 500px:


A: Have a try
separator.autoresizingMask = UIViewAutoresizingFlexibleRightMargin  | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
