菜鸟教程小白 发表于 2022-12-12 16:01:22

ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage


                                            <p><p>在我的所有应用程序中,我都有带有 UIButtonTypeSystem 的 UIButton。
对于 ios7,我想以编程方式设置按钮外观。
对于正常状态,我需要带有蓝色边框颜色的白色背景
<img src="https://dl.dropboxusercontent.com/u/2770480/normalBtnStatus.png" alt="normal state button"/> </p>

<p>对于突出显示的状态,我需要带有蓝色边框颜色的灰色背景
<img src="https://dl.dropboxusercontent.com/u/2770480/highlightedBtnStatusCustom.png" alt="highlighted state button"/> </p>

<p>(对于禁用状态,我需要带有灰色边框的白色背景)</p>

<p>我为每个状态创建了图像(包含背景和边框颜色)并使用 UIButton 的方法 setBackgroungImage:forState: 设置它们。
但是当按钮处于突出显示状态时,我得到了这个按钮样式
<img src="https://dl.dropboxusercontent.com/u/2770480/highlightedBtnStatusSystem.png" alt="actual highlighted state button"/> </p>

<p>我发现克服这种行为的唯一方法是将所有应用程序按钮类型从 UIButtonTypeSystem 更改为 UIButtonTypeCustom。意思是传递所有应用程序xib的</p>

<p>是否有其他方法可以在不更改所有应用程序按钮类型的情况下这样做</p>

<p>谢谢
投资返回率</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您好,您可以像这样以编程方式设置按钮:</p> <pre><code>UIButton *button = ;
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
;
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
];
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/19653531/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/19653531/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIControlStateHighlighted 的 UIButtonTypeSystem setBackgroundImage