iOS UIButton按钮

系统字体

+ ?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

NSArray
*familyNames = [[NSArray
alloc] initWithArray:[UIFont familyNames]];

NSArray
*fontNames;

NSInteger
indFamily, indFont;

for (indFamily=0; indFamily<[familyNames count]; ++indFamily)

{

    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);

    fontNames = [[NSArray
alloc] initWithArray:

            [UIFont fontNamesForFamilyName:

            [familyNames objectAtIndex:indFamily]]];

    for
(indFont=0; indFont<[fontNames count]; ++indFont)

    {

        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);

    }

}

 

Button

  1.

?





1

2

3

4

5

6

7

//iOS 7下给UIButton加边框

[testBtn.layer setMasksToBounds:YES];

[testBtn.layer setCornerRadius:8.0]; //设置矩圆角半径

[testBtn.layer setBorderWidth:1.0];   //边框宽度

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });

[testBtn.layer setBorderColor:colorref];//边框颜色

  2.

?





1

2

3

4

5

6

7

8

9

10

//遍历button改标题

- (void)changeName:(UIButton *)btn{

    for
(NSInteger
i = 0; i < 10; i ++) {

        if
(btn.tag == 10) {

            [btn setTitle:@"我的名字不一样"
forState:UIControlStateNormal];

        }else{

            [btn setTitle:@"一样的"
forState:UIControlStateNormal];

        }

    }

}

 3.关于UIButton,既可以采用setBackgroundImage来设置底部图片,同时也可以采用
setImage方法;

两者还是有一定区别的;
首先setBackgroundImage,image会随着button的大小而改变,图片自动会拉伸来适应button的大小,这个时候当然可以设置button的title,image不会挡住title;
相反的的setImage,图片不会进行拉伸,原比例的显示在button上,此时再设置title,title将无法显示,因此可以根据需求选中方法;

4.

UIButton点击后改变背景的方法

?





1

2

3

4

5

6

7

8

9

10

11

12

//初始设置:

UIImage *bgImg1 = [UIImage imageNamed:@"Selected.png"];

UIImage *bgImg2 = [UIImage imageNamed:@"Unselected.png"];

[btn setImage:bgImg2 forState:UIControlStateNormal];

[btn setImage:bgImg1 forState:UIControlStateSelected];

//然后在button的Action方法改变button状态:

- (IBAction) buttonTouch:(id)sender

{

    UIButton *button = (UIButton *)sender;

    button.selected = !button.selected;

}

一个uiview上多个button,如何判断是哪个按钮被点击了

UIButton
*button = (UIButton *)sender;
1.根据button.tag来区分

2.或者根据button的title 

/****************Label****************************/

label中显示不同颜色的字以及不同字体,字体高亮,Diy
label 

http://www.cocoachina.com/bbs/read.php?tid=69385&keyword=label

改变UILabel里的一段文字的颜色


1.core text    
2.用NSAttributedString  ,...setAttributedText:

给UILabel的文本添加阴影效果

Lable.shadowColor
= color;
 Lable.shadowOffset = CGSizeMake(0,
-1.0);

下拉框的实现
UITableView + UIButton + UILabel

http://www.cocoachina.com/bbs/read.php?tid=110202&keyword=label

UIlabel旋转90度

lb.transform=CGAffineTransformMakeRotation(M_PI/2); 

button取标题值赋值给label

label.text =
button.currenTitle 

-(IBAction)buttonClicked:(id)sender{
    UIButton
*button =
(UIButton*)sender;    //得到你点击的button
    NSString
*buttonTitle =
button.titleLabel.text;    //得到button的title并赋值给string类型的buttonTitle
    (比如你的label名字就叫label的话)
    label.text
= buttonTitle;    //给label赋值
}

 

如何将UILabel中的文字变链接?  FromCOCOchina

自己定义一个类urlLabel

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

#import <Foundation/Foundation.h>

@class URLLabel;

@protocol
MyLabelDelegate <NSObject>

@required

- (void)myLabel:(URLLabel *)myLabel touchesWtihTag:(NSInteger)tag;

@end

@interface
URLLabel : UILabel {

    id
<MyLabelDelegate> delegate;

}

@property
(nonatomic, assign) id
<MyLabelDelegate> delegate;

- (id)initWithFrame:(CGRect)frame;

@end

#import "URLLabel.h"

#define FONTSIZE 13

#define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

@implementation
URLLabel

@synthesize
delegate;

// 设置换行模式,字体大小,背景色,文字颜色,开启与用户交互功能,设置label行数,0为不限制

- (id)initWithFrame:(CGRect)frame {

    if
(self = [super
initWithFrame:frame])

    {

        [self
setLineBreakMode:UILineBreakModeWordWrap|UILineBreakModeTailTruncation];

        [self
setFont:[UIFont systemFontOfSize:FONTSIZE]];

        [self
setBackgroundColor:[UIColor clearColor]];

        [self
setTextColor:COLOR(59,136,195,1.0)];

        [self
setUserInteractionEnabled:YES];

        [self
setNumberOfLines:0];

    }

    return
self;

}

// 点击该label的时候, 来个高亮显示

- (void)touchesBegan:(NSSet
*)touches withEvent:(UIEvent *)event {

    [self
setTextColor:[UIColor purpleColor]];

}

// 还原label颜色,获取手指离开屏幕时的坐标点, 在label范围内的话就可以触发自定义的操作

- (void)touchesEnded:(NSSet
*)touches withEvent:(UIEvent *)event {

    [self
setTextColor:COLOR(59,136,195,1.0)];

    UITouch *touch = [touches anyObject];

    CGPoint points = [touch locationInView:self];

    if
(points.x >= self.frame.origin.x && points.y >= self.frame.origin.y && points.x <= self.frame.size.width && points.y <= self.frame.size.height)

    {

        [delegate myLabel:self
touchesWtihTag:self.tag];

    }

}

- (void)dealloc {

    [super
dealloc];

}

  

完整的超链接的UILabel教程、

http://www.cocoachina.com/bbs/read.php?tid-60903.html

UILabel 触摸操作

http://www.cocoachina.com/bbs/read.php?tid=48942&keyword=label

label实时显示textfield的输入

UILabel *textLabel;
UITextField *textField;

-(BOOL) textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
*)string
{
textLabel.text = [textField.text
stringByAppendingString:string];
return YES;
}

iOS UIButton按钮,码迷,mamicode.com

时间: 2024-08-05 15:24:55

iOS UIButton按钮的相关文章

iOS:UIButton按钮的详解

UIButton的详细介绍: 一.按钮具有的属性: @property(nonatomic,readonly) UIButtonType buttonType;  //按钮形状类型 @property(nonatomic,readonly,retain) NSString *currentTitle;    //按钮当前文字 @property(nonatomic,readonly,retain) UIColor  *currentTitleColor;     //按钮当前文字颜色 @prop

IOS UI-Button按钮

1 #import "ViewController.h" 2 3 @interface ViewController () 4 { 5 UILabel *lable; 6 BOOL moveFlag; 7 NSInteger length; 8 UIButton *btn; 9 NSTimer *timer; 10 } 11 12 @end 13 14 @implementation ViewController 15 16 - (void)viewDidLoad { 17 [supe

简单的UIButton按钮动画效果ios源码下载

这个是简单的UIButton按钮动画效果案例,源码,简单的UIButton按钮动画,可以自定义button属性. 效果图: <ignore_js_op> 使用方法: 详细说明:http://ios.662p.com/thread-2272-1-1.html

使用swift在sprite中显示圆角UIButton按钮

我对objective-C不是很熟,UIKit以前没有用过,SpriteKit也只看了遍教程,然后看了一遍swift语言教程,此时开始编写这个程序,所以遇到的问题比较小儿科,解决方法也是曲线救国,希望有高人指点解决这些问题的简单方法,有好的解决方法后,我会随时进行本日志的修改,以免误导他人. 程序界面很是简单 然后点击中间的游戏区域,会roll色子,随机产生1~6的数字,飞机前进若干步,遇到梯子向前跳若干步,而遇到蛇则后退若干步,指导抵达25格,游戏结束. 上面有一个标签,显示游戏状态和Roll

UIButton 按钮控件

文章出处:http://blog.csdn.net/iukey UIButton是一个标准的UIControl控件,所以如果你对UIControl不甚了解还是先看一下我的另一篇博文:<UIControl IOS控件编程> 一.创建 两种方法: 1. 常规的 initWithFrame UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 80, 44)]; 对代码创建View(UIControl继承自UIView,

IOS UIButton用法详解

这段代码动态的创建了一个UIButton,并且把相关常用的属性都列举了.希望对大家有用.   //这里创建一个圆角矩形的按钮UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 能够定义的button类型有以下6种,// typedef enum {// UIButtonTypeCustom = 0, 自定义风格// UIButtonTypeRoundedRect, 圆角矩形 // UIButtonTy

iOS 防止按钮快速点击造成多次响应的避免方法

有时候有些操作是防止用户在一次响应结束中再响应下一个.但有些测试用户就要猛点,狂点.像这种恶意就要进行防止. 当然有些异步操作时,可以在调用前enable 掉.等CallBACK 后再enable起来.过程中按钮是不能点的. 1.可以使用: - (void) timeEnough { UIButton *btn=(UIButton*)[self.view viewWithTag:33]; btn.selected=NO; [timer invalidate]; timer=nil; } - (v

iOS UIButton同时设置title和image属性

在iOS开发中,使用UIButton设置title和image,达到tabBarItem的效果,即title在下,image在上: 目前,我发现有两种比较好的方法: 方法一,使用UIEdgeInsets UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setFrame:CGRectMake(100, 100, 60, 60)]; [button setBackgroundColor:[UIColor

UIButton按钮类的使用

UIButton按钮类的使用 我要说什么? 1. 什么是按钮 2. 按钮的基本使用 知识点详解 1. 什么是按钮? 如下如所示, 我们很多时候需要在让用户控制我们的应用, 一般可以使用按钮 2. 按钮的使用 //按钮类UIButton的使用 //1.如何创建一个按钮 //创建按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; //设置位置 button.frame = CGRectMake(100, 100, 1