I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below:
From I
I met the same issue. Finally, I solved this by subclassing UIToolbar and override the layout subviews method.
- (void)layoutSubviews {
[super layoutSubviews];
if (leftItem_ && leftItem_.customView
&& [leftItem_.customView isKindOfClass:[UIButton class]]) {
CGRect newFrame = leftItem_.customView.frame;
newFrame.origin.x = 0; // reset the original point x to 0; default is 12, wired number
leftItem_.customView.frame = newFrame;
}
if (rightItem_ && rightItem_.customView
&& [rightItem_.customView isKindOfClass:[UIButton class]]) {
CGRect newFrame = rightItem_.customView.frame;
newFrame.origin.x = self.frame.size.width - CGRectGetWidth(newFrame);
rightItem_.customView.frame = newFrame;
}
}