I'm experiencing really strange issue with monotouch SectionIndex side panel. Basically after adding
public override string[] SectionIndexTitles (UITableView tableView)
to my table data source, I can see side index being correctly populated, although it cuts a bit of my custom cell's background, which makes it look a bit weird (see image below)
I've got UITableView.Appearance.BackgroundColor = UIColor.Clear set in AppearanceManager, which by look of it, SectionIndex inherits, although what I want is to get SectionIndex to stay "on top" without affecting anything below it including my cell's background image.
Am I missing some property that needs to be applied to UITableView?
I spent ages trying to figure out what's missing, but not getting anywhere with it...
Thanks!
screenshot - http://blue-and-orange.net/media/30659/untitled.jpg
OK I found the problem!
Background should not be assigned directly on cell's BackgroundColor property, instead BackgroundView in your custom cell needs to be assigned to - new UIVIew() (which has the background set)
UIView backgroundView = new UIView();
backgroundView.BackgroundColor = UIColor.FromPatternImage(Resources.CinemaListingCellBackground);
BackgroundView = backgroundView;
Related
I have a UICollectionViewController while doing the following:
Return a string array in collectionView:indexPathForIndexTitle:atIndex:
Set cell.contentView.backgroundColor = [UIColor redColor] on collectionView:cellForItemAtIndexPath:
(Notice that changing the background color of the cell is just for demonstrating the issue. The important thing is to show index titles on the right.)
The result (as following displayed) is that the content view takes the entire collection view width and it doesn't being affected (as it should) by the appearance of the index titles.
With UITableViewController I am doing similar steps:
Return a string array in sectionIndexTitlesForTableView:
Set cell.contentView.backgroundColor = [UIColor redColor] on tableView:cellForRowAtIndexPath:
Here, in contrast to the collection view behavior, the content view is "shrinking" as expected as following appear:
Can anyone tell if this is a bug or the expected behavior?
your question is not clear and obvious, but i will try to answer.
First: try to set UITableView's (actually UIScrollView's) property 'showVerticalScrollIndicator' to false (https://developer.apple.com/documentation/uikit/uiscrollview/1619405-showsverticalscrollindicator?language=objc)
Second: try to play with TableView 'contentInset', 'separator inset' properties. Perfectly, you should set 'separatorStyle' to 'none' and use your custom separator-cells, or conditionally set bottom line inside cells (https://developer.apple.com/documentation/uikit/uitableview/1614909-separatorstyle)
Third: check out how to customize Header of Table or Header/Footer of Collection:
https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614901-tableview
https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/1618037-collectionview
One more important thing: you may always Examine a View Hierarchy. Check out this link https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ExaminingtheViewHierarchy.html
I want to achieve next things in my UITableViewController:
Have transparent table Header View with fixed height.
Have solid colored Table Footer View (for example with white color).
To achieve this I need to set my TableViews’ background to clearColor. But once I set whole tableView backgroundColor to clearColor my header and footer also gets transparent, and I don’t need footerView as transparent.
You may say: use TableView inside UIViewController, but I can’t do it, because I’m using static cells with dynamic height, and static TableView will never conform UITableViewDataSource protocol (only way to change cell heights dynamically), because I haven’t got methods like tableView(cellForRowAtIndexPath).
Try setting the tableFooterView property:
tableView.tableFooterView = UIView()
Hope this helps!
Due to our designer being a sadist, I have a UITableView with a segmented control that switches between two different types of cells in separate feeds. The cells are dequeued with different identifiers and classes — this all works fine. The cells share a parent but are different sizes and for optimization reasons I set the layer.shadowpath manually in layoutSubviews() of the parent. I need the shadows: designer's wishes.
The issue is that after I switch to the second segment, some of the way down the table there are shadows dangling from what I believe are the cells above. As you can see from the first image, there are two shadows, and if I scroll down to occlude the top-most visible cell the shadow disappears, which leads me to the believe that the shadows are offset. Further scrolling makes these shadows disappear and not reappear again until switching tabs again. The rest of the shadows are fine.
two shadows
scroll down slightly
When switching back to the previous tab, where the cells are taller, there are also shadow issues, but those shadows are too short. As noted, the code that sets the shadow path is in the parent class, and the parent class is responsible for making and laying-out the top-most "card" view that contains the custom subCells.
I do everything programmatically: setting up the views and the Autolayout. Currently cell heights are hard-coded.
I'm not sure what information is relevant as I am completely at a loss, so here is how I set the shadowPath.
override func layoutSubviews() {
super.layoutSubviews()
cardView.layer.shadowPath = UIBezierPath(rect: cardView.bounds).CGPath
}
For simplicity the card is layout out in the contentView with the following visual format:
"V:|-marginV-[card]-marginV-|"
"H:|-marginH-[card]-marginH-|"
For whatever reason, even though I was using separate classes and separate reuseIdentifiers, the first reused cells just out of the view port were still sized as the tall cells in the other segment. When I changed
let cell = tableView.dequeueReusableCellWithIdentifier(booksReuseIdentifier) as! ProfileBookCell
to include the indexPath as
let cell = tableView.dequeueReusableCellWithIdentifier(booksReuseIdentifier, forIndexPath: indexPath) as! ProfileBookCell the recycling issue was remedied and bounds were properly computed. I tried layoutIfNeeded in a dozen different places to no effect, but this fixed it.
I had the same exact problem and I tried the current marked solution but that, nor anything else seemed to work. After trying so many other things I finally tried moving my add shadow code inside the layoutSubviews function of my subclassed UITableViewCell and it finally worked! I think this worked because the cell's final size isn't always calculated properly until the layouSubviews call and it needs the proper size to draw the shadow.
override func layoutSubviews() {
super.layoutSubviews()
addShadow(cell: self)
}
private func addShadow(cell:UITableViewCell) {
cell.layer.shadowOffset = CGSize(width:1, height:1)
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowRadius = 1
cell.layer.shadowOpacity = 0.6
cell.clipsToBounds = false
let shadowFrame: CGRect = (cell.layer.bounds)
let shadowPath: CGPath = UIBezierPath(rect: shadowFrame).cgPath
cell.layer.shadowPath = shadowPath
}
I have a uitableviewcell with content view containing some custom view.'
When the table view enters edit mode the content view resizes (becomes narrower) there by the image in the content view is shrunk horizontally
Does anyone know how to prevent this ?
I have set the cell indentation to none.
Thanks
Have you tried setting shouldIndentWhileEditing to NO
Take a look at properties :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html
Have you tried setting the auto-resize masks on the view?
theView.autoresizingMask = UIViewAutoresizingNone;
You may need to set it on the content view and/or the image view - it's not clear exactly how your view hierarchy is structured. However, the frame might be set explicitly (rather than auto-resized) by the framework, in which case this won't work.
If you are trying to have a background image for the entire table cell, you may also want to try an alternative method which is to set the backgroundColor of the cell like this:
UIImage* someImage = [UIImage imageNamed:#"someImage"];
cell.backgroundColor = [UIColor colorWithPatternImage:someImage];
Remember to make sure the backgroundColor of all other views you place inside are [UIColor clearColor] so that you can see through to the background image.
You can always get a tableviewcell with an indexpath. Using that tableviewcell reuseidentifier, You can avoid the tableview cell content size to be resized or not. I had a requirement to implement the similar kind of functionality to avoid resizing of seperate cells. PFB the code.
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL shouldIndentWhileEditingRow = NO;
UITableViewCell *lTableViewCell = [tableView cellForRowAtIndexPath:indexPath];
/*Change the position of the target rect based on Sending messages or Receiving messages*/
if ([lTableViewCell.reuseIdentifier isEqualToString:#"SendingChatCellIdentifier"]) {
shouldIndentWhileEditingRow = NO;
}else if ([lTableViewCell.reuseIdentifier isEqualToString:#"ReceivingChatCellIdentifier"]){
shouldIndentWhileEditingRow = YES;
}
return shouldIndentWhileEditingRow;
}
I did something similar to avoid the cell content to be resized when using cell automatic dimension.
My problem was that the textView inside the cell, after the selection, was wrapping its content in more lines, and I just wanted to avoid this.
To solve this "issue":
I added a trailing constraint of 40px (the size of the accessory view) to the cell content
On cell select, i change the constraint to 0, so the text is 40 px larger, but as the accessory shows up, you don't see any changes.
The pro of this solution is that the content dimension is not changing anymore when user select a row.
the con is that you have always 40px of free space on the right of the cell, also when not selected.
I'm working on an app that has lots of UITableViews and I'm trying to give them a textured background color. I need to use the Grouped style because I don't want the section headers to float over the text fields when the user scrolls.
The problem I'm having is that when I use the Grouped style, the background texture doesn't scroll with the table; it stays in place while the table scrolls above it. I feel like this is kind of weird and I would rather have the background scroll with the table, the way it does in the Plain style. Unfortunately, because I can't have the header views floating on top of everything, that doesn't appear to be an option.
Has anyone been able to accomplish this?
Here's some relevant code:
- (void)loadView {
[super loadView];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texturedPattern.png"]];
// this prevents the cells from replicating the background texture
self.tableView.backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// disable the default grouped border since we're doing it manually with the textField
cell.backgroundView = nil;
cell.backgroundColor = [UIColor clearColor];
}
And my table view currently looks like this:
UPDATE
As Amit Vyawahare suggested, I tried applying the background texture to the background of the headers and each cell. There are two problems that are both much more obvious when you see it in motion, but I'll do my best.
First, the background is always visible. I've removed the background color from the table to make it more obvious:
Everywhere you see black, the background texture of the tableView would be visible and it will not scroll with the tableView. The Grouped tableView style inserts the 5 pixel border on either side of every cell and can't be changed. Additionally, there is no footer beneath the Staff ID section, and I've even implemented -tableView:heightForFooterInSection: to return 0.0, but there's still a gap there.
Second, even if I were able to get rid of these gaps, the textures don't line up anyway. Again, this is difficult to see, so I've uploaded a retina screen shot to make it a little easier:
This is most obvious above the Password section, you can see the textures don't align properly and it looks kind of like a "fold" in the paper. Which would be cool, I guess, if that's what the client wanted. It's visible, but less obvious on just about every edge from the second screen shot. This is because the texture is actually quite large: 200x200 (400x400#2x), and there are slight variations in color that aren't noticeable unless this sort of misalignment happens.
First replace your UITableViewController by a UIViewController and add a UITableView to it. Set the autoresizingMask to flexible width/height. Now you have something equivalent to a UITableViewController, but with more control over the view hierarchy.
Then add a view below the tableview (actually: add that one first) which holds the background.
Finally, set the delegate of the scrollview to your class, and respond to scroll events by updating your background view accordingly.