我正在为 iOS 开发一个通用应用程序,因此我必须将标签设置为 center in UIToolBar
。请帮助我做到这一点。
我已经实现的代码
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"dd-MM-yyyy hh:mm a"];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [format stringFromDate:now];
label.text = dateString;