怎么获取UIButton标题?

UIButton在不同状态(被点击\正常状态\不可用\ ...)标题是可以不同的

按钮的状态

typedef NS_OPTIONS(NSUInteger, UIControlState) {
    UIControlStateNormal       = 0,
    UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is set
    UIControlStateDisabled     = 1 << 1,
    UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)
    UIControlStateFocused NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 3, // Applicable only when the screen supports focus
    UIControlStateApplication  = 0x00FF0000,              // additional flags available for application use
    UIControlStateReserved     = 0xFF000000               // flags reserved for internal framework use
};

以下代码获取正常状态下的标题,并赋值给别的变量

UIControlStateNormal为正常状态

- (IBAction)buttonPressed:(UIButton *)sender {
    NSString *title = [sender titleForState:UIControlStateNormal];
    NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.", title];
    _statusLable.text = plainText;
}
时间: 2024-08-09 23:56:15

怎么获取UIButton标题?的相关文章

用EXCEL批量获取网页标题的方法

这段时间准备做淘宝,但不知道卖什么产品,因此想从一些B2B 网站上扒拉一些产品词下来挨个研究,但一个一个的打开网页查看产品太慢太费事,但想到这些产品词都存在于网页标题上,因此想到了用excel来批量获取网页的标题.经过一番查找,在网上找到了两种方法(其实是两组代码). 打开excel找到开发者工具,点击"Visual Basic" 在下图所示位置右键点击添加模块 填入如下代码: Function Title(url As String) As String With CreateObj

How do I get an image from an UIButton? 如何获取uibutton设置的uiimage

UIImage*img =[button imageForState:UIControlStateNormal];How do I get an image from an UIButton? 如何获取uibutton设置的uiimage,码迷,mamicode.com How do I get an image from an UIButton? 如何获取uibutton设置的uiimage

php正则获取网页标题、关键字、网页描述代码

php正则获取网页关键字,代码如下: function get_keywords($html) { $html=strtolower($html); preg_match("@<head[^>]*>(.*?)</head>@si",$html, $regs); $headdata = $regs[1]; preg_match("/<meta +name *=["']?keywords["']? *content=[&qu

Python2获取网页标题

Python获取网页标题 使用Python2.x的urllib2和lxml,速度应该还快于BeautifulSoup4(话说回来,为什么大家都要用BS4呢?一个XPATH不就完了吗) 没有安装过的,用pip安装一下 pip install lxml Shell演示: >> from lxml import etree >> import urllib2 >> page = etree.HTML(urllib2.urlopen('https://blog.csdn.net

自定义带进度条的WebView , 增加获取web标题和url 回掉

1.自定义ProgressWebView package com.app.android05; import android.content.Context; import android.graphics.Bitmap; import android.util.AttributeSet; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; /

获取UIButton的一些属性

获取文字  button.currentTitle 更多如下: @property(nullable, nonatomic,readonly,strong) NSString *currentTitle;             // normal/highlighted/selected/disabled. can return nil @property(nonatomic,readonly,strong) UIColor  *currentTitleColor;        // nor

Jython使用jsoup获取网页标题与链接信息

目的:获取网站链接,可以实现无人工干预的资料获取. 1 java实现的jsoup HTML解析库 下载:http://jsoup.org/ 2 工作平台Ubuntu 3 使用Jython调用jsoup实现提取网页联接信息 代码: #coding=utf-8 #doc from http://jsoup.org/apidocs/ from org.python.core import codecs codecs.setDefaultEncoding('utf-8') import sys #pri

给UILabel 或者 UIButton标题加下划线

方法一: [objc] view plaincopyprint? NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中奖记录"]; NSRange strRange = {0,[str length]}; [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInte

PHP CURL或file_get_contents获取网页标题的代码及两者效率的稳定性问题

PHP CURL与file_get_contents函数都可以获取远程服务器上的文件保存到本地,但在性能上面两者完全不在同一个级别,下面我先来介绍PHP CURL或file_get_contents函数应用例子,然后再简单的给各位介绍一下它们的一些小区别吧. 推荐方法 CURL获取 ? 1 2 3 4 5 6 7 8 9 10 11 12 <?php $c = curl_init(); $url = 'www.jb51.net'; curl_setopt($c, CURLOPT_URL, $ur