zoukankan      html  css  js  c++  java
  • UIButton 设置字体大小

    btn.frame = CGRectMake(x, y, width, height);

    [btn setTitle@"search" forStateUIControlStateNormal];

    //设置按钮上的自体的大小

    //[btn setFont: [UIFont systemFontSize: 14.0]];    //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法

    //应该使用

    btn.titleLabel.font = [UIFont systemFontOfSize14.0];

    [btn seBackgroundColor: [UIColor blueColor]];

    //最后将按钮加入到指定视图superView

    [superView addSubview: btn];

     

    附:创建按钮的两种方法:

    1、动态创建
    btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btnfont setFrame:CGRectMake(100, 10, 120, 40)];
    [btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
    [btnfont setTitle:@"字体" forState:UIControlStateNormal];
    btnfont.backgroundColor=[UIColor clearColor];
    [self.view addSubview:btnfont];
    2、在xib文件中已经创建好,通过tag获取按钮
    UIButton *testButton= (UIButton*)[self.view viewWithTag:100];
    [testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];

    注册事件
    -(void) test: (id) sender{

    UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"ceshi" message:@"test11111" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];

    [av show];

    }

  • 相关阅读:
    java线程
    windows Server 安装
    nginx正则反向代理
    crontab定时任务启动脚本失败
    数据结构
    异常概念
    shell日期遍历复制文件
    多态和抽象
    图1 列出连通集
    PTA 代码注意事项
  • 原文地址:https://www.cnblogs.com/mekor/p/4021293.html
Copyright © 2011-2022 走看看