English 中文(简体)
UIButton在选择可调用的电文时就得到保险。
原标题:UIButton gets covered when UITableViewCell is selected

我用UIButton在我的UITableViewCell内,可以选择这个 but子,选择金星和未经选择的光球。

“entergraph

The problem is that when ever the cell is selected, no matter if the button is selected or not it will turn to a gray color (this gray color is different than the gray color of unselected mode of the star). I ve been trying to figure out why this happens, but had no luck.

“entergraph

here is the implementation of the cells,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];    
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom]retain];

//set the background of the cells
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"cellBackground.png"]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellselected2.png"]];

// set the button content
[button setImage:[UIImage imageNamed:@"star.png" ] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"starSelected.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(selectedButton:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(280, 10,  24, 24)];

[cell addSubview:button];

return cell;
}

也是当我主在选定牢房时的纽顿将彻底消失!

感谢

最佳回答

我描述了问题。 问题是,当单元被选定时,牢房中的UIButton将去“亮度状态”。 如果在纽特州没有被分配使用的形象,那么它就会发现与我的情况一样。

因此,我只是通过在UIButton着重指出的州增加我喜欢使用的图像而确定,

[button setImage:[UIImage imageNamed:@"starSelected.png"] forState:UIControlStateHighlighted];

希望有助于面临同样问题的其他人:

问题回答

你们正在将ton子添加到囚室框架中,而不是其内容。 观点。

UITableViewCell adds the value of this property as a subview only when the cell is selected. It adds the selected background view as a subview directly above the background view (backgroundView) if it is not nil, or behind all other views. Whilest a UITableViewCell adds the background view as a subview behind all other views and uses its current frame location.

替换

[cell addSubview:favButton];

iii

[cell.contentView addSubview:favButton];

这一点应当解决。

便携式电文Cell物体的内容观点是该电池显示的内容的缺省表面。 如果你想通过简单地增加其他观点来定制电池,那么你就应当把电池添加到内容观点中,以便随着电池向编辑方式过渡和从编辑方式过渡,能够适当定位。

它全都载于AmpapDocs ^。

Ref:

You can certainly set the image for the highlighted state. Another option, if you want to use the same image for UIControlStateNormal and UIControlStateHighlighted you can also say button.adjustsImageWhenHighlighted = NO, the default is YES.





相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...

热门标签