为UIButton设置矩形边框

时间:2011-08-29 10:34:49

标签: iphone uibutton

我必须实现一个带有矩形边框的按钮,它应该是这个enter image description here

我正在使用以下代码执行此操作:

-(void)createDynamicView:(CGRect)frame{

UIButton *drugimgBtn        = [UIButton buttonWithType:UIButtonTypeCustom];
drugimgBtn.frame            = frame;//CGRectMake(0, 0, 155, 130);
NSString *myurl = responseDrugInfo.ThumbImg;   //by rajesh
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myurl]];
UIImage *tbImage = [[UIImage alloc] initWithData:imageData];
[drugimgBtn setBackgroundImage:tbImage forState:UIControlStateNormal];
[drugimgBtn addTarget:self action:@selector(imageButtonAction:) forControlEvents:UIControlEventTouchUpInside];

UIView * prescView          = [[UIView alloc]init];
prescView.frame             = frame;
prescView.layer.borderColor = [UIColor lightGrayColor].CGColor;
prescView.layer.borderWidth = 1.0f;
[prescView addSubview:drugimgBtn];

[scrollview addSubview:drugimgBtn];
//[prescView release];


[myurl release];
[tbImage release];


}

输出如下:enter image description here

如何实现矩形边框,使其在第一张图像中显示为相同?

0 个答案:

没有答案