Iam creating a custom TableView Cell Which has some text and a Background image. when i select the cell then the image should chnage but this is not hapening, i have use following code so some one help me?
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected)
[self.imgSelected setImage:[UIImage imageNamed:#"listing-gradient-hover.png"]];//Image that i want on Selection
else
[self.imgSelected setImage:[UIImage imageNamed:#"listing-gradient.png"]];
//Normal image at background everytime table loads.
// Configure the view for the selected state
}
This is not working for me.
Try the following:
initialize an UIImageView to be the background view and an UIImageView to be the selected background view when you setup ypu custom table view cell:
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"listing-gradient-hover.png"]];
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"listing-gradient.png"]];
UITableViewCell adds the value of the selectedBackgroundView 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. Calling setSelected:animated: causes the selected background view to animate in and out with an alpha fade. You do not need to override this method just for switching the background image upon selection.
Related
I'm having an issue receiving touches in UICollectionViews contained within UITableViewCells. The desired effect is a UITableView with n rows of horizontally scrolling UICollectionViews. The view is displaying correctly but the collection views only receive touches in the top 44px. I imagine that the table view is still in the process of initialization when the collection views are created and that the collection views are using UITableView's default cell height when setting up their gesture recognizers. Relevant code is below.
In my UITableViewCell subclass, I create a container view for the UICollectionView:
- (void)layoutSubviews
{
if (!_collectionViewContainer) {
_collectionViewContainer = [[CVTCollectionViewContainer alloc] init];
_collectionViewContainer.frame = self.bounds;
[self.contentView addSubview:_collectionViewContainer];
};
}
In my container view, I instantiate a UICollectionView:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
if (!self.collectionView) {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.backgroundColor = [UIColor clearColor];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize = CGSizeMake(130.0, 130.0);
[_collectionView registerClass:[CVTCollectionViewCell class] forCellWithReuseIdentifier:#"Collection view cell"];
[self addSubview:self.collectionView];
}
}
There's nothing interesting in my UITableViewController, just that I return 200 in tableView:heightForRowAtIndexPath:
It occurred to me that the layoutSubviews method of my UITableViewCell subclass may be the wrong place for initialization of the 'container' view for my UICollectionView. But, when I NSLog(#"cell: %#", self); in layoutSubviews, the cell's frame shows the desired height (200). Still, I have a feeling that I am doing my setup for the collection view too early, but I can't think of where else I might perform this work.
So, the gist: how can I add a UICollectionView to a UITableViewCell and make sure that the UICollectionView's gesture recognizers respond in the entirety of the collection view, rather than just the top 44 px?
Thanks in advance, as always.
Bit of a facepalm here, I was using a UITableViewController that was created in storyboard but mostly configured in code. In storyboard, I had not set the row height of the table view, so it was still at the default 44 px. Of course, the table view looked at IB for its initial config so, although tableView:heightForRowAtIndexPath: was being called and the cells were displaying correctly, the initial height set in IB was affecting how the cell's subviews were created.
I made a popover containing sectioned tableView with some background. I want to remove that thin vertical border line, which is present on sides between two sections.
set view's background color or image to your custom color/image then and set tableview's background to nil. It should work.
- (void)viewDidLoad
{
[super viewDidLoad];
//background image
self.view.backgroundColor= [UIColor clearColor];
self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"yourimage.png"]];
//table background image, mytableview should be your tableView's name you can try self.tableView if you have not set/delegate anything to it.
self.mytableView.backgroundView = nil;
}
I want change color of this view. I want tabbar more button view color same as app color,not white. how it is possible.
Fo this you have to customize moreNavigationController. One solution is to subclass your UITabBarController and add following on - (void)viewDidLoad method.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationController *moreController = self.moreNavigationController;
//if u want to custamize navigationBar u can customize
//moreController.navigationBar
if ([moreController.topViewController.view isKindOfClass:[UITableView class]]) {
//Custamize your tableview here
UITableView *tableView = (UITableView *)moreController.topViewController.view;
//Change the color of tableView
[tableView setBackgroundColor:[UIColor redColor]];
moreController.topViewController.view = tableView;
}
}
I hope this helps you
to customize the tabBarItem you can follow other answers.
I would like to draw my own edit accessory view instead of the red minus button in a UITableView.
Strangely setting any of them in tableView: cellForRowAtIndexPath: has no effect
cell.editingAccessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"cancel"]];
since the button is set before calls to that.
Thank you
In order for the editing controls to be seen, editing needs to be enabled in the table view.
Try sending this to the table view: - (void)setEditing:(BOOL)editing animated:(BOOL)animate.
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/setEditing:animated:
I have grouped table view. I want to add UISegmentedControl in table cell with clear background so that it will be displayed as FOOTER . How can I do this? I tried using clearColor. But it's not working.
Set the background view with a clear UIView object like so:
UIView *clearView = [[UIView alloc] initWithFrame:CGRectZero];
[clearView setBackgroundColor:[UIColor clearColor]];
[self setBackgroundView:clearView];
[clearView release];
And make sure you set cell selection style to none.
Edit: added some square brackets