按下时如何使iOS Button提供视觉反馈? [英] How to make iOS Button give visual feedback when pressed?

查看:100
本文介绍了按下时如何使iOS Button提供视觉反馈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个iOS 7应用程序,我知道Apple的新设计指南要求大量平面设计极简主义的东西,但是此应用程序并非真正针对精通技术的人群,因此Apple的指南提出了一个问题.我有一个普通的按钮,上面只有文字,我想在其周围放一个轮廓,我也想让按钮对被按下产生反应,以便人们实际上知道它是一个按钮,因此当按钮将它们带到其他应用程序时,它们不会惊慌吗?那我该怎么办

I am making an iOS 7 app, I know that Apple's new design guidelines call for a bunch of flat design minimalist stuff, but this app is not really targeted at the tech-savvy crowd, so apple's guidelines pose a problem. I have a regular button, with just text in it, and I would like to put an outline around it, and I would also like for the button to react to being pressed, so that people actually know it is a button, and so that they do not freak out when the button takes them to a different app? So how do I

  1. 在常规的iOS按钮周围放置轮廓?

  1. Put an outline around a regular iOS button?

使用常规的iOS按钮可以为按下按钮提供一些简单的视觉反馈吗?

Make a regular iOS Button give some simple visual feedback to being pressed?

推荐答案

如果您使用情节提要(界面生成器)来设计应用程序,则非常简单:

If you are using a storyboard (interface builder) for designing your app it's quite easy:

  1. 创建UIButton的子类.我们称它为XYBorderButton.

  1. Create a subclass of UIButton. Let's call it XYBorderButton.

在XYBorderButton.m中添加方法:

In XYBorderButton.m add the methods:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self makeBorder];
    }
    return self;
}

- (void)makeBorder {
    self.layer.cornerRadius = 10.0;
    self.layer.borderColor = [UIColor blueColor];
    self.layer.borderWidth = 1.0;
}

然后在界面构建器中选择按钮并将其类更改为XYBorderButton

Then in interface builder select the button and change its class to XYBorderButton

例如,可以通过更改按钮的背景颜色和/或更改其字体颜色来提供视觉反馈.

You can give visual feedback for example by changing the button's background color and/or by changing its font color.

使用Interface Builder设置这些属性非常容易: 只需选择按钮,然后在状态配置下拉菜单中选择状态突出显示",并根据需要设置背景颜色和字体颜色.

Setting these attributes is quite easy with Interface Builder: Just select the button, then choose the state "Highlighted" in the state config dropdown menu and set the background color and font color as desired.

这篇关于按下时如何使iOS Button提供视觉反馈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆