• <bdo id='4an8N'></bdo><ul id='4an8N'></ul>
    1. <i id='4an8N'><tr id='4an8N'><dt id='4an8N'><q id='4an8N'><span id='4an8N'><b id='4an8N'><form id='4an8N'><ins id='4an8N'></ins><ul id='4an8N'></ul><sub id='4an8N'></sub></form><legend id='4an8N'></legend><bdo id='4an8N'><pre id='4an8N'><center id='4an8N'></center></pre></bdo></b><th id='4an8N'></th></span></q></dt></tr></i><div id='4an8N'><tfoot id='4an8N'></tfoot><dl id='4an8N'><fieldset id='4an8N'></fieldset></dl></div>
    2. <small id='4an8N'></small><noframes id='4an8N'>

      1. <legend id='4an8N'><style id='4an8N'><dir id='4an8N'><q id='4an8N'></q></dir></style></legend>

        <tfoot id='4an8N'></tfoot>

        来自带有自定义图像的 UIButtons 的自定义 UIBarButtonItems - 是否可以使点击目标更大?

        时间:2023-07-08

          1. <small id='7P7Z8'></small><noframes id='7P7Z8'>

            1. <i id='7P7Z8'><tr id='7P7Z8'><dt id='7P7Z8'><q id='7P7Z8'><span id='7P7Z8'><b id='7P7Z8'><form id='7P7Z8'><ins id='7P7Z8'></ins><ul id='7P7Z8'></ul><sub id='7P7Z8'></sub></form><legend id='7P7Z8'></legend><bdo id='7P7Z8'><pre id='7P7Z8'><center id='7P7Z8'></center></pre></bdo></b><th id='7P7Z8'></th></span></q></dt></tr></i><div id='7P7Z8'><tfoot id='7P7Z8'></tfoot><dl id='7P7Z8'><fieldset id='7P7Z8'></fieldset></dl></div>

                <tbody id='7P7Z8'></tbody>
              • <bdo id='7P7Z8'></bdo><ul id='7P7Z8'></ul>
                <legend id='7P7Z8'><style id='7P7Z8'><dir id='7P7Z8'><q id='7P7Z8'></q></dir></style></legend>
                • <tfoot id='7P7Z8'></tfoot>
                  本文介绍了来自带有自定义图像的 UIButtons 的自定义 UIBarButtonItems - 是否可以使点击目标更大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作 UIBarButtons 如下:

                  I'm making UIBarButtons as follows:

                  // Create "back" UIBarButtonItem
                  UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
                  backButton.frame = CGRectMake(0, 0, 28, 17);
                  [backButton addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
                  backButton.showsTouchWhenHighlighted = YES;
                  
                  UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
                  [backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
                  
                  UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
                  
                  [toolBarItems addObject:backBarButtonItem];
                  

                  但是,点击目标很小.更准确地说,它们是自定义图像的大小.(同样,它们很小.)有什么方法可以增加它们的点击目标的大小吗?

                  However, the tap targets are tiny. More precisely, they're the size of the custom images. (Which again, are tiny.) Is there any way to increase the size of their tap target?

                  (注意:改变 UIButtons 的 frame 属性只会拉伸图像.)

                  (Note: altering the frame property of the UIButtons just stretches the image.)

                  推荐答案

                  对您的代码稍作改动即可解决问题

                  Small changes to your code will do the stuff

                  需要更改:

                  • 我假设 backButtonImage 的大小为 {28,17} 并将按钮框架设置为 CGRectMake(0, 0, 48, 37) `
                  • 删除 backGroundImage 并使用 setImage:
                  • 将属性 imageEdgeInsets 设置为 UIEdgeInsetsMake(10, 10, 10, 10)
                  • I am assuming that the size of backButtonImage is {28,17} and setting the button frame as CGRectMake(0, 0, 48, 37) `
                  • remove the backGroundImage and use setImage:
                  • set the property imageEdgeInsets to UIEdgeInsetsMake(10, 10, 10, 10)

                  你的代码会变成这样:

                  UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
                  backButton.frame = CGRectMake(0, 0, 48, 37);
                  [backButton addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
                  backButton.showsTouchWhenHighlighted = YES;
                  
                  UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
                  [backButton setImage:backButtonImage forState:UIControlStateNormal];
                  
                  backButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
                  
                  UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
                  
                  [toolBarItems addObject:backBarButtonItem];
                  

                  您可以根据需要更改 frameimageEdgeInsets 的值.
                  这段代码对我有用.

                  You can change the value for the frame and the imageEdgeInsets as per your requirements.
                  This code worked for me.

                  这篇关于来自带有自定义图像的 UIButtons 的自定义 UIBarButtonItems - 是否可以使点击目标更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在另一个 xib 中使用 xib 对象 下一篇:UIButton 标题左对齐问题 (iOS/Swift)

                  相关文章

                • <tfoot id='NLVZl'></tfoot>
                • <legend id='NLVZl'><style id='NLVZl'><dir id='NLVZl'><q id='NLVZl'></q></dir></style></legend>

                    <small id='NLVZl'></small><noframes id='NLVZl'>

                      • <bdo id='NLVZl'></bdo><ul id='NLVZl'></ul>
                      <i id='NLVZl'><tr id='NLVZl'><dt id='NLVZl'><q id='NLVZl'><span id='NLVZl'><b id='NLVZl'><form id='NLVZl'><ins id='NLVZl'></ins><ul id='NLVZl'></ul><sub id='NLVZl'></sub></form><legend id='NLVZl'></legend><bdo id='NLVZl'><pre id='NLVZl'><center id='NLVZl'></center></pre></bdo></b><th id='NLVZl'></th></span></q></dt></tr></i><div id='NLVZl'><tfoot id='NLVZl'></tfoot><dl id='NLVZl'><fieldset id='NLVZl'></fieldset></dl></div>