I have made a UITableViewCell with xib, inside it I have made a UIView and made IBoutlet in my custom tableViewCell class. I want to set the border color of that UIView.
My code in tableViewCell.h:
#property (weak, nonatomic) IBOutlet UIView *circleView;
In tableViewCell.m:
#import "OUSTProfileTableViewCell.h"
#implementation OUSTProfileTableViewCell
//#synthesize circleView = _circleView;
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
self.circleView.layer.cornerRadius = 3; // this value vary as per your desire
self.circleView.layer.masksToBounds = YES;
self.circleView.layer.borderWidth = 2.0;
self.circleView.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor lightGrayColor]);
}
return self;
}
#end
But it's not working.
Put code inside
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.circleView.layer.cornerRadius = 3; // this value vary as per your desire
self.circleView.layer.masksToBounds = YES;
self.circleView.layer.borderWidth = 2.0;
self.circleView.layer.borderColor = [UIColor lightGrayColor].CGColor;
}
Related
I create a class named SWTextView and it inherits from UITextView. It does nothing but add a placeholder label. When I initialize a SWTextView and put it in a UITableViewCell, it's not editable even when the editable property of the SWTextView is YES. Does anyone have met the same problem?
The SWTextView is as follow:
#import <UIKit/UIKit.h>
#interface SWTextView : UITextView
- (void)setPlaceholder:(NSString *)placeholder;
#end
#interface SWTextView ()
#property(nonatomic, strong) UILabel *placeholderLabel;
#end
#implementation SWTextView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self = [super initWithFrame:frame]) {
_placeholderLabel = [[UILabel alloc] init];
_placeholderLabel.textColor = [UIColor grayColor];
[self addSubview:_placeholderLabel];
self.font = [UIFont systemFontOfSize:12];
}
return self;
}
- (void)setFont:(UIFont *)font
{
[super setFont:font];
_placeholderLabel.font = font;
}
- (void)setPlaceholder:(NSString *)placeholder
{
_placeholderLabel.text = placeholder;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[_placeholderLabel sizeToFit];
}
#end
I have a custom cell that I have made in the iterfacebuilder and connected to my .h file.
And then in my CustomCell.m file I have
#implementation TwoMealsTableViewCell
#synthesize dayLabel, firstMealBtn, secondMealBtn, indexPath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
dayLabel.textColor = [UIColor orangeColor];
if (self) {
dayLabel.textColor = [UIColor orangeColor];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
And I have the cell all set up in the tableview, and I see the buttons, and labels, but I don't see the color change?
Why is this.
Thanks for the help in advance!!!
This will change the cell color
dayLabel.textColor = [UIColor orangeColor];
I have subclassed UIControl to create my own class. I am trying to override setHighligheted: but for some reason it doesn't get called...
I have double checked and none of my subviews have userInteractionEnabled = NO. Are there any other methods that I should override?.
Thank you!
Here is some sample code:
#import "Booking.h"
#interface BookingCloud : UIControl
// Booking
#property(nonatomic, strong) Booking *booking;
// BackgroundView
#property (strong, nonatomic) IBOutlet UIView *backgroundView;
And the implementation
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setUpSubViews];
}
return self;
}
- (void)setUpSubViews {
[[NSBundle mainBundle] loadNibNamed:#"BookingCloud" owner:self options:nil];
[self addSubview:backgroundView];
self.frame = backgroundView.frame;
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if (highlighted) {
backgroundView.backgroundColor = [[Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:#"background_color"]] colorWithAlphaComponent:0.8];
} else {
backgroundView.backgroundColor = [[Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:#"background_color"]] colorWithAlphaComponent:1];
}
}
Let's say i have created myTableViewCell class:
#import "MyTableViewCell.h"
#implementation MyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
UIImageView *imgSponsor=[[UIImageView alloc ] initWithFrame:CGRectMake(0,0,self.bounds.size.width,200)];
imgSponsor.image = [UIImage imageNamed:#"imageFirstCell"];
[self.contentView addSubview:imgSponsor];
}
return self;
}
[...]
#end
Can I set a default height for this cell from within this class apart from running through the associated tableviewcontroller method (heightForRowAtIndexPath..)?
You can use like in MyTableViewCell.h-
-(void)layoutSubviews {
self.frame = //Define your frame;
[super layoutSubviews];
}
I'm setting the backgroundColor of my UITableViewCell like this:
cell.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:#"background.png"]];
It looks fine except for the "end caps" of the cell. The end caps (where the rounded corners start) are colored differently like the middle portion of the cell. Do I need to provide images for the end caps too?
not really sure what the end caps are. but i would say if ur using an image for your cell it should take up the whole cell. and you should be defining the size of your cells at that point. see layout subviews below for what i mean
#import "CustomCell.h"
#implementation CustomCell
#synthesize primaryLabel,myImageView;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:20];
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:myImageView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,0, 40, 40);
myImageView.frame = frame;
frame= CGRectMake(boundsX+70 ,5, 200, 25);
primaryLabel.frame = frame;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[myImageView release];
[primaryLabel release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end