天天看点

UINavigationController添加文字与UIButton添加文字图片

    //导航栏上添加字体

    self.navigationItem.leftBarButtonItem=[[[UIBarButtonItemalloc] initWithTitle:@"返回"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(pushAction)]autorelease];

   UILabel *customLab = [[UILabelalloc] initWithFrame:CGRectMake(0,0, self.view.frame.origin.x/2,30)];

    [customLab setTextColor:[UIColorwhiteColor]];

    [customLabsetText:@"我的导航"];

    customLab.font = [UIFontboldSystemFontOfSize:30];

    self.navigationItem.titleView = customLab;

    //按钮上添加图片和文字

    UIButton *pauseBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [pauseBtn setImage:[UIImageimageNamed:@"btn_red_small"]forState:UIControlStateNormal];

    [pauseBtn setImage:[UIImageimageNamed:@"btn_red_small_press"]forState:UIControlStateHighlighted];

    pauseBtn.frame =CGRectMake(250,30, 65, 30);

    [pauseBtn addTarget:selfaction:@selector(pauseAction:)forControlEvents:UIControlEventTouchUpInside];

   UILabel *text = [[UILabelalloc]init];

    text.frame = pauseBtn.bounds;

    text.text =@"点击";

    text.textAlignment =NSTextAlignmentCenter;

    text.font = [UIFontsystemFontOfSize:25];

    text.textColor = [UIColorwhiteColor];

    [pauseBtnaddSubview:text];

    [self.viewaddSubview:pauseBtn];