iOS UIBarButtonItem UIEdgeInsetsMake不影响右/左的大小

时间:2017-06-14 04:03:18

标签: ios objective-c

我正在尝试缩小使用UIEdgeInsetsMake创建图像的按钮。它似乎在顶部/底部工作并垂直缩小图像,但右/左似乎没有效果。

以下是我创建图像并尝试缩小图像的方法。知道我哪里错了吗?

    NSString *path = [NSString stringWithFormat: @"https://s3.amazonaws.com/ios/images/remove-symbol-white.png"];
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *homeButton = [[UIImage alloc] initWithData:data];


    //TODO: Check image exists
    self.doneButton = [[UIBarButtonItem alloc] initWithImage:[homeButton imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                                style:UIBarButtonItemStylePlain
                                                               target:self
                                                               action: @selector(doneButtonPushed:)];
    self.doneButton.imageInsets = UIEdgeInsetsMake(12, 12, 12, 12);

2 个答案:

答案 0 :(得分:0)

您可以将视图设置为初始化UIBarButtonItem,如下所示:
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:imageView]; 所以你可以设置你想要的UIImageView大小。

答案 1 :(得分:0)

取消上述答案,我解决了这个问题:

    NSString *path = [NSString stringWithFormat: @"https://s3.amazonaws.com/ios/images/remove-symbol-white.png"];
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *homeButton = [[UIImage alloc] initWithData:data];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[homeButton imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    imageView.frame = CGRectMake(0, 0, 20, 20);

    self.doneButton = [[UIBarButtonItem alloc] initWithCustomView:imageView];