我在字典中的值,這將使一個UIButton設置的UIButton幀不工作
tags = (
{
height = "15.513672";
text = jeans;
width = "39.808105";
x = "225.500000";
y = "265.000000";
},
{
height = "15.513672";
text = jacket;
width = "44.080078";
x = "190.000000";
y = "156.500000";
}
);
我設置uibuttons的框架上,讓值從字典
for (int i = 0; i<[tags count]; i++) {
NSLog(@"adding tags");
NSMutableDictionary *propertiesdict = [[NSMutableDictionary alloc] init];
propertiesdict = [[tags objectAtIndex:i] mutableCopy];
float x = [[dict objectForKey:@"x"] floatValue];
float y = [[dict objectForKey:@"y"] floatValue];
float width = [[dict objectForKey:@"width"] floatValue];
float height = [[dict objectForKey:@"height"] floatValue];
NSString *title = [dict objectForKey:@"text"];
UIButton *button = [[UIButton alloc] init];
[button setFrame:CGRectMake(x, y, width, height)];
[button setTitle:title forState:UIControlStateNormal];
button.layer.cornerRadius = 2.5;
//button.alpha = 0.9;
[button.titleLabel setFont:[UIFont systemFontOfSize:13]];
[button setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
button.tag = i;
[button addTarget:self action:@selector(tappedOnTag:) forControlEvents:UIControlEventTouchUpInside];
[tagsView addSubview:button];
}
加入後的框架按鈕到子視圖,NSLog顯示每個按鈕都有一個框架(0,0,0,0),它與我在for循環中設置框架時不同。
2015-10-15 12:25:17.787 kyss[1018:316548] tapped on tags view. Number of subviews = 2. Subviews: (
"<UIButton: 0x15f732330; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x15f72eb60>>",
"<UIButton: 0x15f6d10e0; frame = (0 0; 0 0); opaque = NO; tag = 1; layer = <CALayer: 0x15f6b3790>>"
)
循環內部的'x','y','width'和'height'的值是否正確? – rmaddy
@rmaddy是的,NSLog顯示2015-10-15 12:52:22.447 kyss [1044:324386]添加標籤 2015-10-15 12:52:22.447 kyss [1044:324386]屬性字典= { height = 「15.513672」; text = jacket; width =「44.080078」; x =「190.000000」; y =「156.500000」; } – dwizzylion
這不能回答我的問題。實際的'x','y','width'和'height'變量是否正確?你似乎正在記錄'properiesDict'(它是從'tags'創建的),但你從'dict'得到了值。 – rmaddy