小编him*_*man的帖子

对齐UIButton的文本?

我正在生成一些按钮.在按钮中,我显示日期和用户给出的引用ID.我希望这些数据在按钮中保持对齐.

我尝试过的:

[button.titleLabel setTextAlignment:UITextAlignmentLeft]; 
button.titleLabel.textAlignment = UITextAlignmentLeft;
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

 - (void)viewDidLoad
{
 [super viewDidLoad];
 [scrollView setScrollEnabled:YES];
 [scrollView setContentSize:CGSizeMake(320, 500)];

int i = 0;

for (CalculatorData *data in calcDatas) {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];


    button.frame = CGRectMake(1 , 20 + i*40, 295, 30);

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM/dd/yyyy HH:MM:SS"];

    NSString *dateString = [dateFormat stringFromDate:data.updateDate];

    NSString *title = [NSString stringWithFormat:@"%@ : %@",dateString,[data dataKey]];


    [button setTitle:title forState:UIControlStateNormal];


    [button addTarget:self action:@selector(buttonPressed:)
    forControlEvents:UIControlEventTouchUpInside];
    button.tag = data.calcId;


    [scrollView addSubview:button];
    i++;
}
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c uibutton

12
推荐指数
2
解决办法
2万
查看次数

如何在Objective C中将NSDate转换为毫秒?

例如:假设NSDate tempdate = "05-23-2013".我希望将此值转换为毫秒.

如何使用Objective C执行此操作?

objective-c nsdate

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

objective-c ×2

iphone ×1

nsdate ×1

uibutton ×1

xcode ×1