053点击按钮后改变按钮的文字

效果如下:

ViewController.h

1 #import <UIKit/UIKit.h>
2
3 @interface ViewController : UIViewController
4 @property (strong, nonatomic) UIButton *btnState;
5
6 @end

ViewController.m

 1 #import "ViewController.h"
 2
 3 @interface ViewController ()
 4
 5 - (void)disableStateSwitch:(UISwitch *)sender;
 6 @end
 7
 8 @implementation ViewController
 9
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     self.view.backgroundColor = [UIColor whiteColor];
13     self.navigationItem.title = @"点击按钮后改变按钮的文字";
14     UISwitch *swtDisableState = [[UISwitch alloc] init];
15     swtDisableState.on = YES;
16     [swtDisableState addTarget:self action:@selector(disableStateSwitch:) forControlEvents:UIControlEventValueChanged];
17     UIBarButtonItem *barBtnDisableState = [[UIBarButtonItem alloc] initWithCustomView:swtDisableState];
18     [self setToolbarItems:@[barBtnDisableState] animated:YES];
19
20     _btnState = [UIButton buttonWithType:UIButtonTypeCustom];
21     _btnState.frame = CGRectMake(0, 0, 200, 60);
22     _btnState.center = self.view.center;
23     _btnState.backgroundColor = [UIColor colorWithRed:0.513 green:0.894 blue:1.000 alpha:1.000];
24     _btnState.layer.masksToBounds = YES;
25     _btnState.layer.cornerRadius = 10.0;
26     _btnState.layer.borderColor = [UIColor colorWithRed:1.000 green:0.572 blue:0.894 alpha:1.000].CGColor;
27     _btnState.layer.borderWidth = 2.0;
28     //设置按钮标题字体及阴影颜色
29     _btnState.titleLabel.font = [UIFont boldSystemFontOfSize:22];
30     _btnState.titleLabel.shadowOffset = CGSizeMake(2.0, 2.0);
31     //设置普通状态下的显示特征
32     [_btnState setTitle:@"点我" forState:UIControlStateNormal];
33     [_btnState setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
34     [_btnState setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
35     //设置按钮被触摸时,即高亮状态下的显示特征
36     [_btnState setTitle:@"变样子了" forState:UIControlStateHighlighted];
37     [_btnState setTitleColor:[UIColor brownColor] forState:UIControlStateHighlighted];
38     [_btnState setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
39     //设置按钮非活性(无效)状态下的显示特征
40     [_btnState setTitle:@"禁用按钮了" forState:UIControlStateDisabled];
41     [_btnState setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
42     [_btnState setTitleShadowColor:[UIColor blackColor] forState:UIControlStateDisabled];
43     [self.view addSubview:_btnState];
44 }
45
46 - (void)didReceiveMemoryWarning {
47     [super didReceiveMemoryWarning];
48     // Dispose of any resources that can be recreated.
49 }
50
51 - (void)viewWillAppear:(BOOL)animated {
52     [super viewWillAppear:animated];
53     [self.navigationController setNavigationBarHidden:NO animated:animated];
54     [self.navigationController setToolbarHidden:NO animated:animated];
55 }
56
57 - (void)disableStateSwitch:(UISwitch *)sender {
58     _btnState.enabled = sender.on;
59 }
60
61 @end

AppDelegate.h

1 #import <UIKit/UIKit.h>
2
3 @interface AppDelegate : UIResponder <UIApplicationDelegate>
4 @property (strong, nonatomic) UIWindow *window;
5 @property (strong, nonatomic) UINavigationController *navigationController;
6
7 @end

AppDelegate.m

 1 #import "AppDelegate.h"
 2 #import "ViewController.h"
 3
 4 @interface AppDelegate ()
 5 @end
 6
 7 @implementation AppDelegate
 8
 9 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
10     _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
11     ViewController *viewController = [[ViewController alloc] init];
12     _navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
13     _window.rootViewController = _navigationController;
14     [_window addSubview:_navigationController.view];
15     [_window makeKeyAndVisible];
16     return YES;
17 }
18
19 - (void)applicationWillResignActive:(UIApplication *)application {
20 }
21
22 - (void)applicationDidEnterBackground:(UIApplication *)application {
23 }
24
25 - (void)applicationWillEnterForeground:(UIApplication *)application {
26 }
27
28 - (void)applicationDidBecomeActive:(UIApplication *)application {
29 }
30
31 - (void)applicationWillTerminate:(UIApplication *)application {
32 }
33
34 @end
时间: 2024-11-01 04:40:19

053点击按钮后改变按钮的文字的相关文章

Android点击按钮后改变颜色

1.在res文件夹下新建一个文件夹drawable 2.在drawable文件夹下面建立一个xml文件:button_selector.xml <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/normal" android:state_pressed="false"/&g

点击按钮后禁止按钮并显示文字[正在处理...], getelementbyid button标签 text 赋值

[转载注明出处:lanmanck.net.csdn.blog] 网上说用jquery,其实getelementbyid就可以搞定了. 另外,鄙视百度搜出来的一大堆垃圾,搜索 getelementbyid button标签 text 赋值 居然出来一堆的input提交按钮,唉,真是无语! 看原问题及答案: http://stackoverflow.com/questions/12679813/how-to-change-button-text-or-link-text-in-javascript

【jQuery】鼠标接触按钮后改变图片

1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 <% 4 String path = request.getContextPath(); 5 Str

Jquery点击发送按钮后,按钮文本倒计时

1.html代码 <input type="number" id="mobileNo" placeholder="请输入手机号" /> <input type="button" id="btnGetCode" style="background-color:#68BE02;color: #FFFFFF;border:0 solid #ccc;margin-bottom: 5%;w

点击按钮后到底发生了什么,Touch,LongClick或者Click?

按钮点击事件详解 最近一个项目需要给应用初始界面上的动态按钮添加在不同状态的变换效果,如点击(俗一点也可称为按压)后实现背景图的更换或者图标的缩放等效果.由于按钮点击的时间有长有短,所以采用OnTouchListener监听器对点击事件进行监听,并利用对应的onTouch(View v, MotionEvent event)方法来实现按钮图标的变换效果(背景图更换或者图标缩放).但是项目中除了利用Touch事件来处理按钮基本的变换外,还需要响应LongClick或者Click事件来为用户做进一步

cocos2d-x:解决点击拖动按钮后,所在的layer监听不到触摸事件的问题

点击拖动按钮后,想让所在的layer监听到屏幕的触摸事件,可以把该按钮拖动开始的时候设置setTouchEnabled为false;例: #include "ui/UIButton.h" bool myDemo::init() { // 设置点击事件 EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(

android imageButton 点击按钮前中后,按钮颜色的变化

我们在开发的过程中,往往为了美化界面的需要,会修改按钮的默认外观,而因为Android中的按钮有三种状态—默认,被点击,被选中.所以,如果要改变按钮的外观,需要对这三种情况都做出修改,也许在以往,我们最容易想到的就是,手动监听按钮的选中和点击事件,然后写代码来替换按钮的背景,但是在android中,我们不需要这么麻烦,android早就替我们想好了解决方案,那就是selector资源.如果我们要实现按钮的三种背景,只需在res/drawable目录中建立这样一个XML文件: selector.x

【翻译自mos文章】当点击完 finish按钮后,dbca 或者dbua hang住

当点击完 finish按钮后,dbca 或者dbua hang住 来源于: DBCA/DBUA APPEARS TO HANG AFTER CLICKING FINISH BUTTON (文档 ID 727290.1) 适用于: Oracle Database Configuration Assistant - Version 10.2.0.1 to 11.2.0.1 [Release 10.2 to 11.2] Information in this document applies to a

点击jQuery Mobile的按钮改变颜色

jquery-mobile-移动 我有这样的代码来改变点击一个按钮的颜色: $('.fav').live('click', function(e) { $(this).buttonMarkup({ theme: "b" }); }); 我怎样才能再次单击该按钮返回到正常颜色(C)? 有没有办法看到一个按钮的状态? 因为它是活的,那么你可以只让自己的切换: $('.fav').live('click', function() { var dotoggle = $(this).attr(&