Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在表格视图的右角设置图像_Ios_Objective C_Ipad_Ios5 - Fatal编程技术网

Ios 在表格视图的右角设置图像

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 {

如何在表格视图右角设置UIImage。我正在使用table view制作iPad应用程序,并显示联系人列表。单击“联系人表”视图时,希望显示右侧详细信息。。。在这里,我想把一个图像,这是在表视图选择

有人给我这个建议吗

谢谢

看到我的代码了吗

-(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。我认为有三种解决方案:

  • 向渐变背景图像添加半透明条带(如果您使用图像,但似乎您也可以使用CoreGraphics渐变)
  • 渐变背景不应该是cell.backgroundView,而是其子视图,即较小的cell.backgroundView(可能与您的arroy和Strengch图像一起)
  • 重写单元格的layoutSubviews方法,使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>change
    x
    值,可能是
    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?