Ios 在表格视图的右角设置图像
如何在表格视图右角设置UIImage。我正在使用table view制作iPad应用程序,并显示联系人列表。单击“联系人表”视图时,希望显示右侧详细信息。。。在这里,我想把一个图像,这是在表视图选择 有人给我这个建议吗 谢谢 看到我的代码了吗Ios 在表格视图的右角设置图像,ios,objective-c,ipad,ios5,Ios,Objective C,Ipad,Ios5,如何在表格视图右角设置UIImage。我正在使用table view制作iPad应用程序,并显示联系人列表。单击“联系人表”视图时,希望显示右侧详细信息。。。在这里,我想把一个图像,这是在表视图选择 有人给我这个建议吗 谢谢 看到我的代码了吗 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
![enter image description here][1]
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(347, 0.5, 14, 48)];
imv.image=[UIImage imageNamed:@"activeBg.png"];
[cell.selectedBackgroundView addSubview:imv];
}
预期产出:
我的输出:
使用的图像:
更改x值后查看此输出:
尝试使用属性
[view setClipsToBounds:NO];
我不确定您必须在哪个位置设置此否,但请尝试设置self.view、UITableView或Cell.首先,请小心使用浮点坐标,因为它们可能看起来很模糊 UITableViewCell的宽度是多少?应根据单元格大小计算坐标:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect rectImageView = CGRectMake(cell.frame.size.width - 14, 1, 14, 48); // maybe even y and height is calculateable
UIImageView *imv = [[UIImageView alloc]initWithFrame:rectImageView];
imv.image=[UIImage imageNamed:@"activeBg.png"];
[cell.selectedBackgroundView addSubview:imv];
[cell setClipsToBounds:NO]; // do not clip subviews
}
此外,setClipsToBounds很重要,如果我的记忆正常,则默认为YES…渐变背景是cell.backgroundView?看起来你们的activeBg.png在右边是半透明的,你们可以通过它看到cell.backgroundView。我认为有三种解决方案:
在
viewDidLoad:
方法中写入这两行
arrowImage = [UIImage imageNamed:@"image"];
[tableView setClipsToBounds:NO];
现在,您必须在didSelectRowAtIndexPath:
中执行以下操作:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self addArrowToIndexPath:indexPath];
}
这里是方法定义:
-(void)addArrowToIndexPath:(NSIndexPath *)indexPath
{
CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
if (arrowView)
{
[arrowView removeFromSuperview];
arrowView = nil;
}
// arrowView is an UIImageView declared globally
arrowView = [[UIImageView alloc] initWithImage:arrowImage];
rect.origin.x = CGRectGetMaxX(rect);
rect.size = arrowImage.size;
[arrowView setFrame:rect];
[tableView addSubview:arrowView];
}
注意:还要设置行高=箭头image.size.height,即它可以适合单元格高度。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return arrowImage.size.height;
}
您可以直接下载
CGRectMake(347,0.5,14,48)
中的.p>changex
值,可能是355
CGRectMake(352,0.5,14,48)我使用了这个代码hey@Swathi检查我的答案,…..您的观点正在剪辑它<代码>[查看setClipsToBounds:否]代码>让所有人都看到视图层次结构cgrect rectmageview=CGRectMake(cell.frame.size.width-6,1,14,48);//甚至y和高度都是可计算的UIImageView*imv=[[UIImageView alloc]initWithFrame:rectImageView];imv.image=[UIImage ImageName:@“activeBg.png”];[cell.selectedBackgroundView addSubview:imv];[单元格设置ClipsToBounds:否];//不要剪辑子视图我使用了这段代码,但是图像角隐藏…您是否尝试过在表视图及其容器上设置clipsToBounds=NO?