//昵称
UIButton *nickBut = [UIButton buttonWithType:UIButtonTypeCustom];
nickBut.userInteractionEnabled = YES;
[nickBut setFrame:CGRectMake(0, 0, 100, 30)];
[nickBut addTarget:self action:@selector(selectGroup) forControlEvents:UIControlEventTouchUpInside];
[nickBut setTitle:@"勇敢的心" forState:UIControlStateNormal];
navItem.titleView = nickBut;
CGSize fontSize =[nickBut.titleLabel.text sizeWithFont:[UIFont systemFontOfSize:16]
forWidth:120
lineBreakMode:UILineBreakModeTailTruncation];
nickBut.frame = CGRectMake(0, 0, fontSize.width + 16, fontSize.height);
根据UIButton的title,和字体,动态获取UIButton的宽度
UIButton *nickBut = [UIButton buttonWithType:UIButtonTypeCustom];
nickBut.userInteractionEnabled = YES;
[nickBut setFrame:CGRectMake(0, 0, 100, 30)];
[nickBut addTarget:self action:@selector(selectGroup) forControlEvents:UIControlEventTouchUpInside];
[nickBut setTitle:@"勇敢的心" forState:UIControlStateNormal];
navItem.titleView = nickBut;
CGSize fontSize =[nickBut.titleLabel.text sizeWithFont:[UIFont systemFontOfSize:16]
forWidth:120
lineBreakMode:UILineBreakModeTailTruncation];
nickBut.frame = CGRectMake(0, 0, fontSize.width + 16, fontSize.height);
根据UIButton的title,和字体,动态获取UIButton的宽度