AQGridViewCell transparent background - objective-c

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.

Related

How to set BarChartView barColor?

This is the UI Picture
I don't know how to set a lightgray color
I try to use
self.chartView.drawGridBackgroundEnabled = YES;
self.chartView.gridBackgroundColor = [UIColor grayColor];
But the effect is not what I want
You have to enable BarShadow Property as mention below:
_barChartView.drawBarShadowEnabled = YES;
By default its showing GrayColor for customize Shadow Color you have to set shadow color in BarChartDataSet like below :
BarChartDataSet *set1 = [[BarChartDataSet alloc] initWithValues:Values];
set1.barShadowColor = [UIColor lightGrayColor]; // Set your custom color here
Hope this will help you to show your Custom color in bar shadow.
You can use
UIColor *color = ...;
color = [color colorWithAlphaComponent:0.5f];
OR You can try with RGB values.
[UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1]

Can't set image as the background of UILabel

I have seen lots of questions in stackoverflow with the same issue, but none of the solutions helped me. I have used the following code to set a custom image as the background of a label:
labelBackgroundImageOriginal = [UIImage imageNamed:#"paper.jpg"];
labelBackgroundImageSize = myLabel.frame.size;
UIGraphicsBeginImageContext(labelBackgroundImageSize);
[labelBackgroundImageOriginal drawInRect:CGRectMake(0, 0, labelBackgroundImageSize.width, labelBackgroundImageSize.height)];
labelBackgroundImageNew = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
myLabel.backgroundColor = [UIColor colorWithPatternImage:labelBackgroundImageNew];
But the label background was still white and the image didn't show up. Then I tried with the various solutions that were given under different questions like the following one by one:
myLabel.backgroundColor = [UIColor clearColor];
myLabel.opaque = NO;
But none of them seem to be working as well. Is there actually a way out of this?
Have you try using [UIColor colorWithPatternImage:] directly with your image ? It works fine for me.
UILabel *test = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 300, 100)];
test.text = #"TEST";
test.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"anyPicture"]];
[self.view addSubview:test];
EDIT : I've tried your code and it works fine ! Have you checked if myLabel.frame.size value is not null ?

Alternating colors for iOS UIViews (like when used in a tablerow)

This code is not working but I think it is very close. I haven't been able to get the many permutations I tried to work. Is this even possible?
myView.backgroundColor = [UIColor (i % 2) == 0 ? cyanColor : whiteColor];
Has anyone tried this or know how this code can be corrected?
That won't work that way.
You need to write
myView.backgroundColor = (i % 2 == 0)? [UIColor cyanColor] : [UIColor whiteColor];

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

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.

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];