UITableViewCell curve line anomaly- left side. What's causing this? Image included - objective-c

I have this odd semicircle being drawn at the top left of each cell in this Table View. I can't seem to be able to get rid of it. I'm not doing any custom drawing in my cells, although the cells are all subclasses of UITableViewCell.
The curved artifact appears only in the first cell in each section, and is still persistent regardless of the table view background.
This is all the custom code in the cell, the rest is in IB
- (void)layoutSubviews {
// NSLog(#"DataEntryCell layoutSubviews");
UILabel *topLabel = [self parameterLabel];
UILabel *bottomLabel = [self dataLabel];
topLabel.font = [UIFont boldSystemFontOfSize:18.0];
topLabel.textAlignment = UITextAlignmentCenter;
topLabel.textColor = [UIColor darkGrayColor];
topLabel.shadowColor = [UIColor lightGrayColor];
topLabel.shadowOffset = CGSizeMake(0.0, 1.0);
bottomLabel.font = [UIFont systemFontOfSize:16.0];
bottomLabel.textAlignment = UITextAlignmentLeft;
bottomLabel.textColor = [UIColor darkGrayColor];
bottomLabel.numberOfLines = 0;
bottomLabel.lineBreakMode = UILineBreakModeWordWrap;
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.autoresizesSubviews = YES;
}
Any idea what could causing this?
Thanks

I don't see anything in that layoutSubviews that really belongs there. All of those properties on the labels should be set when the labels are created. Ditto for the properties on self. The selectionStyle in particular seems suspicious since it mentions gray and you have a stray gray line. By the time layoutSubviews is called, it's too late to set autoresizesSubviews; autoresizing happens before you receive layoutSubviews.
Try putting that stuff closer to the cell's initialization - in awakeFromNib if you're loading the cell (and its subviews) from a nib, or with the code that creates and adds the subviews.

Related

Custom navbar titleView won't clear previous titles before loading new ones

So I created a custom UINavigationItem category to be able to make a custom titleview for my navbar, but everytime I push/pop a view, it simply adds the new title without getting rid of the old one causing the title to just be a jumble of letters. Here's the relevant code:
#implementation UINavigationItem (CustomNavigationItem)
-(UIView *)titleView
{
[self setTitleView:nil];
UILabel *newTitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 220, 32)];
newTitleView.center = CGPointMake(160, 22);
newTitleView.backgroundColor = [UIColor clearColor];
newTitleView.textColor = [UIColor whiteColor];
newTitleView.textAlignment = UITextAlignmentCenter;
newTitleView.text = self.title;
newTitleView.textAlignment = UITextAlignmentCenter;
return newTitleView;
}
#end
You have to remove the old uilabel from its superview, by setting to nil it doesn't do that. That's why you are messing the letters on screen. I also do not think you are getting a recursion, because you are caling the setter, but I maybe wrong.
A quick thing you could is to assign a tag to your newest created view.
[[self.view viewWithTag:YourCustomEnumTag] removeFromSuperView];
// create your view....
textView.tag=YourEnumCustomTag;

AQGridViewCell transparent background

I have a problem customizing my AQGridViewCell. I'd like to have the whole cell having a transparent background, but the following inside of the initWithFrame:reuseIdentifier does not do the job:
self.backgroundView.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.backgroundView.opaque = NO;
self.contentView.opaque = NO;
self.opaque = NO;
Does anyone have an idea how to solve this?
Thank you very much for any response!
EDIT
I found this, but this does not seem to work either:
https://github.com/AlanQuatermain/AQGridView/pull/108#issuecomment-3610006
The tip in your link was half way there. The following did the trick for me:
self.contentView.backgroundColor = nil;
self.backgroundColor = nil;
And you need to put this in your custom AQGridViewCell's initWithFrame:reuseIdentifier:. It's a bit puzzling that you have to set two properties but at least it works.
Also note that you also need to set the background color to clear for all text labels you might have, e.g:
captionLabel.backgroundColor = [UIColor clearColor];
Setting label background to nil doesn't help - it comes out as black.

UITableViewCell custom selectedBackgroundView background is transparent

I have the following code that creates a UIView that I assign to my UITableViewCell's selectedBackgroundView property. Everything works as expected, with the exception of the subview's background, which is transparent.
I use the same code to create a custom view that I assign to backgroundView, and that works fine.
What is causing that subview to be transparent for selectedBackgroundView, and how can I avoid that?
- (UIView*) makeSelectedBackgroundView
{
// dimensions only for relative layout
CGRect containerFrame = CGRectMake(0, 0, 320, 40);
UIView* containerView = [[UIView alloc] initWithFrame:containerFrame];
containerView.autoresizesSubviews = YES;
// dimensions only for relative layout
CGRect subframe = CGRectMake(5, 5, 310, 30);
UIView* subview = [[UIView alloc] initWithFrame:subframe];
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
subview.backgroundColor = [UIColor redColor];
subview.layer.cornerRadius = 5;
subview.layer.borderWidth = 2;
subview.layer.borderColor = [UIColor greenColor].CGColor;
[containerView addSubview:subview];
return containerView;
}
As we can see from name of ivar selectedBackgroundView, this background shown by cell when it was selected.
I've to reload few methods (– setSelected:animated: and – setHighlighted:animated:) of UITableViewCell subclass to reset background color of subviews back to their values. Look's like UIKit do some magic in this template methods (iterating over all UIView subclasses and set their background to clearColor)
This code might be helpful for you:
UIImageView *cellImageView = [[UIImageView alloc]
initWithFrame:CGRectMake(0,
0,
cell.frame.size.width,
cell.frame.size.height
)];
cellImageView.contentMode = UIViewContentModeScaleAspectFit;
// normal background view
[cellImageView setImage:[UIImage imageNamed:#"*<ImageName>*"]];
[cell addSubview:cellImageView];
[cell sendSubviewToBack:cellImageView];
[cellImageView release], cellImageView = nil;
Here cell is an object of custom UITableViewCell.
Also you can set backgroundColor property.
I would try to set the alpha for both containerView and subView to 1.0
[containerView setAlpha:1.0];
...
[subview setAlpha:1.0];
this should make your controls totally opaque.
You could also create some images for the background and use that images in state of creating 2 views. Let's say you create 2 image (normalBackground.png and selectedBackground.png) and then set this images as cell background. Here is a nice tutorial.
Try setOpaque:YES on your views.
In the end, I ended up subclassing UITableViewCell which contained a custom view object, and that worked.

Making UITableView with cell-sized images smooth scrolled

EVERYTHING WRITTEN HERE ACTUALLY WORKS RIGHT
EXEPT FOR [UIImage imageNamed:] METHOD USAGE
Implementation
I am using model in witch you have a custom UITableViewCell with one custom UIView set up as Cell's backgroundView.
Custom UIView contains two Cell-sized images (320x80 px), one of which is 100% transparent to half of the view. All elements are set to be Opaque and have 1.0 Alpha property.
I don't reuse Cells because I failed to make them loading different images. Cell's reused one-by-one up to 9 cells overall. So I have 9 reusable Cells in memory.
Cell initWithStyle:reuseIdentifier method part:
CGRect viewFrame = CGRectMake(0.0f, 0.0f, 320.0f, 80.0f);
customCellView = [[CustomCellView alloc] initWithFrame:viewFrame];
customCellView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self setBackgroundView:customCellView];
CustomCellView's initialization method:
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.opaque = YES;
self.backgroundColor = [UIColor UICustomColor];
}
return self;
}
Images are being pre-loaded to NSMutableArray as UIImage objects from PNG files with UIImage's imageNamed: method.
They are being set in UITableViewDelegate's method tableView:cellForRowAtIndexPath: and passed through UITableViewCell with custom method to UIView.
And then drawn in UIView's drawRect: overridden method:
- (void)drawRect:(CGRect)rect {
CGRect contentRect = self.bounds;
if (!self.editing) {
CGFloat boundsX = contentRect.origin.x;
CGFloat boundsY = contentRect.origin.y;
CGPoint point;
point = CGPointMake(boundsX, boundsY);
if (firstImage) { [firstImage drawInRect:contentRect blendMode:kCGBlendModeNormal alpha:1.0f]; }
if (secondImage) { [secondImage drawInRect:contentRect blendMode:kCGBlendModeNormal alpha:1.0f]; }
}
}
As you see images are being drawn with drawInRect:blendMode:alpha: method.
Problem
Well, UITableView can't be scrolled at all, it's being struck on every cell, it's chunky and creepy.
Thoughts
Well digging sample code, stackoverflow and forums gave me thought to use OpenGL ES to pre-render images, but, really, is it that hard to make a smooth scrolling?
What's wrong with just using UIImageViews? Are they not fast enough? (They should be if you're preloading the UIImages).
One thing to note is that [UIImage imageNamed:] won't explicitly load the image data into memory. It'll give you a reference which is backed by the data on disk. You can get around this by making a call to [yourImage CGImage].

Changing UITableViewCell textLabel background color to clear

In my app I have a table view with customViewCells. I subclassed the UITableViewCell class and added an image that will load async and for the text I use cell.textLabel.text = #"someThext".
For the cells the background color is set alternatively to [UIColor darkGrayColor] and [UIColor whiteColor].
When I run the app in the simulator and on the phone the textLabel of the cell has the background white. I want to set it to be clear, because I want the background color of the cell to be full not a strip then white then another strip.
In the init method of my custom cell I added, hoping that the white will turn into red, but it doesn't have any effect:
[self.textLabel setBackgroundColor:[UIColor redColor]];
I tried also:
self.textLabel.backgroundColor = [UIColor redColor];
But this also didn't work... if I add a UILabel as a subview, the background color of the label can be set, but I don't want to do that because when I rotate the phone I want my labels to auto enlarge.
Any ideas why setting the background color of cell.textLabel doesn't work?
Thank you
If you do not want to subclass UITableViewCell you can just add this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];
}
The problem is that UIKit sets the cell background color in the -setSelected method. I had the method but didn't have self.textLabel.backgroundColor = [UIColor clearColor]; self.detailTextLabel.backgroundColor = [UIColor clearColor]; in it so I added them and the problem mentioned in the picture was fixed.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
self.textLabel.backgroundColor = [UIColor clearColor];
self.detailTextLabel.backgroundColor = [UIColor clearColor];
}
Looks like Apple changed something here. Doing exactly this in iOS4 works:
self.textLabel.backgroundColor = [UIColor xxxColor];
self.detailTextLabel.backgroundColor = [UIColor xxxColor];
At least up to the point that the label background is transparent or takes the background color. Still not possible to set an own background color.
Nice that this is fixed, but a bit surprising during tests if you develop with base SDK 4.1 and min. deployment 3.1 for iPhone classic and iPad.
To set a clear background color you can use clearColor:
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
Is this what you mean?
see this post: How do I set UITableViewCellSelectionStyle property to some custom color?
in your case just use a UIView with white background color
I didn't try it but here's a guess... In order to draw faster the opaque property of the label might be set to true by default.
Try
cell.titleLabel.opaque = NO;
cell.titleLabel.backgroundColor = [UIColor clearColor];
If that doesn't work either I would probably just give up at this point and create my own UILabel for the cell.
to set the color of the textlabel you should do this:
t.textColor = [UIColor colorYouWantRGB];