UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)]; UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)]; titleLabel.text = @"Exercise"; titleLabel.textColor = [UIColor whiteColor]; [titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]]; titleLabel.textAlignment = NSTextAlignmentCenter; [titleView addSubview:titleLabel]; self.navigationItem.titleView = titleView;
出来的效果是这样: