Section cell shows separator on device but not in simulator - objective-c

In my UITableView I set the separatorStyle to UITableViewCellSeparatorStyleNone because in each row I want to show a set of pictures and it should like a grid without any separators.
In the simulator it looks like I want it to, but on my iPad (Version 5.0.1) I get a white line at the bottom of the HeaderCell. When I change the separatorColor to black the white line changes to black, which proves that it really is the separator. So it looks like my custom section view has a separator while the rows inside the sections do not.
I can "trick" the iPad to not show the separator when I define the header's height to 99 instead of 100 but that clearly is not the way to do it.

separatorColor = [UIColor clearColor]; ?

While I don't have the exact answer to your question, perhaps I can point you in the right direction for solving this issue.
I guess you've created custom cells? It sounds to me that it has something to do with the cell frame. In the speedy table view cell code from Tweetie I remember seeing the following code:
- (void)setFrame:(CGRect)newFrame
{
[super setFrame:newFrame];
CGRect bounds = self.bounds;
bounds.size.height -= 1; // keep space for de cell seperator
cellView.frame = bounds;
}
Perhaps Apple's default UITableViewCell code act the same when a frame is set and you could override it.

Related

iOS7 Type into UITextView with Line Spacing and keep formatting using TextKit

I came across this great example which helped me understand how I can achieve line spacing / paragraph spacing as you type inside a UITextView with iOS7, however there is a problem and I am hoping someone can help me with resolving an issue as I am still learning about TextKit please.
This is the actual example
https://github.com/downie/DoubleSpacedTextView
I have attached 2 files:-
1- This is a video of the problem:-
http://1drv.ms/1o8Rpd2
2- This is the project I am testing with:
http://1drv.ms/1o8RtK0
The issue is when there are blank lines between the text lines (at least 2 blank lines) and then click inside the blank lines to activate the UITextView and show the keyboard, the text moves up / loses its formatting.
This is the core function which I modified slightly from the original and it does the formatting, it works perfectly but not when you click inside the UITextView the first time:-
- (void) formatText
{
__block CGFloat topOffset = 0;
NSRange lineGlyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
[self.layoutManager
enumerateLineFragmentsForGlyphRange:lineGlyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *textContainer, NSRange glyphRange, BOOL *stop)
{
CGRect adjustedRect = rect;
CGRect adjustedUsedRect = usedRect;
adjustedRect.origin.y = topOffset;
adjustedUsedRect.origin.y = topOffset;
[self.layoutManager setLineFragmentRect:adjustedRect forGlyphRange:glyphRange usedRect:adjustedUsedRect];
topOffset += 30; // 30 is the space between the lines you can adjust this as you like
}];
CGRect adjustedExtraLineFragmentRect = self.layoutManager.extraLineFragmentRect;
CGRect adjustedExtraLineFragmentUsedRect = self.layoutManager.extraLineFragmentUsedRect;
adjustedExtraLineFragmentRect.origin.y = topOffset;
adjustedExtraLineFragmentUsedRect.origin.y = topOffset;
[self.layoutManager setExtraLineFragmentRect:adjustedExtraLineFragmentRect usedRect:adjustedExtraLineFragmentUsedRect textContainer:self.textContainer];
}
Can you please see if we can stop this from happening? so that the text is always formatted as we type into the UITextView.
Are there any other examples that show how we can type a formatted text (with line spacing) into a UITextView using TextKit or attributed Text?.
I have been struggling with this problem since iOS6.
Thanks,
Will
I don't have a full solution, just ideas of where to look for the solution.
All of the layout code fires off of the textChange event of the UITextView. Moving the cursor around doesn’t change any of the content of that text, so none of that code is called. However, even attaching it to textViewDidChangeSelection doesn’t make the issue go away.
I’m thinking it could be one of two things:
The NSLayoutManager is handling a blank line differently than a line with text. This either means it’s a TextKit bug, or it’s one of the many delegates/methods that just isn't being called.
Something about the rect math is wrong for a blank line. I believe the only key difference in layout if the line is blank vs not is that the usedRect for the lineFragmentRect has width 0, but maybe it’s also got height 0 or a bad offset that’s messing with the math. I don’t really see what’s causing that though.

UILabel gets hidden behind UIImageView

I have made a subclass for UITableViewCell and I am implementing Subtitle TableViewCell with a thumbnail image.
Following are the UITableViewCell contents:
The issue I am facing is when the data loads in TableViewCell, the subtitleLabel text gets hidden upto the height of the imageView. But when I select any Cell, it shows subtitleLabelText completely.
I have added the screenshot of the same for complete reference:
The UIImageView has frame = CGRectMake(0,0,40,40);
Try to give a clearColor background color for the cell title label -
cell.textLabel.backgroundColor = [UIColor clearColor];
It turns out I was using TableViewCell style as subtitle instead of custom. The style settings in subtitle was making the other labels to hide below them. What a silly miss!
In your nib or storyboard file, make sure that the label is below the image view in the list of subview components (it is in the left of the screen). The first subview in that list will be at the lowest level (behind every other subview, if they overlap).
write one line of code
Titlelabel.backgroundcolor = [UIColor ClearColor];
because your label has white background..and Titlelabel height is too large so label is colliding.
Let me know working or not!!!
Happy Coding!!!
What is the frame of Title Label? if its height is more, then also it may possible that it hides your subtitle Label
Here's a great tutorial which helped me when I was trying to do something like you want :
http://www.appcoda.com/ios-programming-customize-uitableview-storyboard/
You can adapt the size of the different components (ImageView, TitleLabel, Subtitle,...)

Removing Custom UITableviewCell border

I have a tableview in my iPhone project. Each cell of the row is customized with a separate UITableViewCell.
The custom cell contains an imageview and a label. My row height is 55 and hence my custom table height is also 55. Imageview lies as a background for the cell, so imageview height is also 55. But when i run the project i could see a border around each row, which seems the custom cell is having a rectangular border around its contents.
How could i be able to remove this bounding rectangle. i am working in xcode 4.2.1 and simulator 5.0.
its possible that the border you see is the seperator, try to add this line to your code
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Is it the cell separator?
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
You need to set the background view of cell-
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
actually it was due to the image i loaded.. it had a shadow part, which appeared as the white space.. sorry for the trouble. THANK YOU ALL

UILabel text overrun in custom tableCell

I have a weird problem in a custom UITableCell subClass.This custom cell has a pair of UILables that are multi-line and can contain varying amounts of text (up to 2000 characters). The custom tableCell has a layout method where I am calculating their frame's height using the code below, taking the device orientation into account:
if (isPortrait) {
presentationTextLabelSize = [presentationTextStr sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(portraitDescriptionWidth, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
presentationTextLabelRect = CGRectMake(60.0f, 25.0f, portraitDescriptionWidth, presentationTextLabelSize.height);
} else {
presentationTextLabelSize = [presentationTextStr sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(landscapeDescriptionWidth, 2000.0f) lineBreakMode:UILineBreakModeWordWrap];
presentationTextLabelRect = CGRectMake(60.0f, 25.0f, landscapeDescriptionWidth, presentationTextLabelSize.height);
}
self.presentationTextLabel.frame = presentationTextLabelRect;
I have the label's autoResizeMask set as follows:
self.presentationTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
I use the same calculation in the UITableViewController to set the row height.
Everything works perfectly, the label is sized to the correct height for it's width, and the cell autoResizes on device rotation, except that when the device is rotated to landscape the label's text sometimes extends out of the label's frame to the right, clear past the edge of the tableView. If I scroll the cell out of view and back again it's back to normal. I am logging the cell's width to the console, and it is correct, yet the text extends far past that width.
Any ideas what's joing on?
Thanks
The problem is, the tableView is not reloaded when the device is rotated to landscape. So, there is mismatch in updating the texts. Use [tableView reloadData]; at the place, where you find the device is changed to landscape mode.

Repeat a semi-transparent NSImage

In a project I'm working on, I have 3 images: top, middle, and bottom. Top and bottom are fixed height, and middle should be repeated in between the two. (The window size will be changing.) They all are tinted with a color from the user preferences, then need to have their alpha set using a value from the preferences.
I can do pretty much everything. The part I get stuck at is drawing the middle. I decided using [NSColor +colorWithPaternImage:] would be the easiest thing to use. There's a lot of code that makes the actually images and colors, so just assume they exist and are not nil.
int problem; // just to help explain things
float alpha;
NSImage *middleTinted;
NSRect drawRect = [self bounds];
drawRect.size.height = self.bounds.size.height - topTinted.size.height - bottomTinted.size.height;
drawRect.origin.y = topTinted.size.height;
NSColor* colorOne = [NSColor colorWithPatternImage:middleTinted];
NSColor* colorTwo = [colorOne colorWithAlphaComponent:alpha];
if(problem == 1)
{
[colorOne set];
}
else if(problem == 2)
{
[colorTwo set];
}
[NSBezierPath fillRect:drawRect];
Assuming problem == 1, it draws the correct image, in the correct location and with the correct size, but no alpha. (Obviously, since I didn't specify one.)
When problem == 2, I'd expect it to do the same thing, but have the correct alpha value. Instead of this, I get a black box.
Is there a solution that will repeat the image with the correct alpha? I figure I could just draw the image manually in a loop, but I'd prefer a more reasonable solution if one exists.
I expect the problem is that pattern colors don't support -colorWithAlphaComponent:.
NSCell.h contains a method called NSDrawThreePartImage that does the work of drawing end caps and a tiled image in between. It also has an alphaFraction parameter that should meet your needs.
If that doesn't work for you, then you might get the pattern color approach to work by re-rendering your middleTinted image into a new NSImage, using the desired alpha value. (See NSImage's draw... methods.)