如果我使用此代码将图像放置在另一个按钮上而没有间距,我不知道如何水平对齐按钮(x轴)。
这是我用过的代码。提前感谢答案。
private static final Pattern matchPat = Pattern.compile("Hello(xyz)*Hello");
String line = "HelloxyzxyzxyzHello";
Matcher x8 = matchPat.matcher(line);
答案 0 :(得分:1)
试试这段代码:
NSArray *arr1 = [pJson1 objectForKey:@"Response"];
int x ;
for (int i=0; i<arr1.count; i++)
{
UIButton *btnNew = [[UIButton alloc]initWithFrame:CGRectMake(x,20, 50, 30)];
btnNew.backgroundColor = [UIColor blackColor];
NSString *str = [NSString stringWithFormat:@"%@",[[arr1 objectAtIndex:i]objectForKey:@"name"]];
[btnNew setTitle:str forState:UIControlStateNormal];
CGSize stringsize = [str sizeWithFont:[UIFont systemFontOfSize:14]];
//or whatever font you're using
btnNew.tag = i;
[self.categoryView addSubview:btnNew];
x += 55;
}