Assigning images to individual parts of a "TableView"
So imagine that I have a tableview that we're calling "section view" which
is divided up into 4 different sections. As you can see from my header
file I've created a UIView for section object that will display all of my
content for the view:
@protocol SectionView;
@class Singleton;
@interface SectionView : UIView{
//Singleton Object
Singleton *singletonObj;
NSMutableArray *images;
UIImageView *images1;
}
@property (nonatomic, retain) UILabel *sectionTitle;
@property (nonatomic, retain) UIButton *discButton;
@property (nonatomic, assign) NSInteger section;
@property (strong, nonatomic) UIImageView *images1;
@property (strong, nonatomic) NSArray *image;
@property (nonatomic, weak) id<SectionView> delegate;
- (id)initWithFrame:(CGRect)frame WithTitle: (NSString *) title
Section:(NSInteger)sectionNumber delegate: (id <SectionView>) delegate;
- (void) discButtonPressed : (id) sender;
- (void) toggleButtonPressed : (BOOL) flag;
@end
@protocol SectionView <NSObject>
@optional
- (void) sectionClosed : (NSInteger) section;
- (void) sectionOpened : (NSInteger) section;
@end
and in my implementation file I have all the properties laid out for the
layout; however, I'm having difficulty being able to assign images to
individual parts of the section. So I need a DIFFERENT IMAGE for each
SECTION. Here's the implementation file:
- (id)initWithFrame:(CGRect)frame WithTitle: (NSString *) title
Section:(NSInteger)sectionNumber delegate: (id <SectionView>) Delegate{
self = [super initWithFrame:frame];
if (self) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer
alloc] initWithTarget:self action:@selector(discButtonPressed:)];
[self addGestureRecognizer:tapGesture];
self.userInteractionEnabled = YES;
self.section = sectionNumber;
self.delegate = Delegate;
CGRect LabelFrame = self.bounds;
LabelFrame.size.width -= 50;
CGRectInset(LabelFrame, 0.0, 5.0);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,
3,LabelFrame.size.width, LabelFrame.size.height)];
label.text = title;
label.font = [UIFont fontWithName:@"MyriadPro-Regular" size:19.0];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:70/255.0 green:70/255.0
blue:70/255.0 alpha:1.0];
label.textAlignment = UITextAlignmentLeft;
[self addSubview:label];
self.sectionTitle = label;
CGRect buttonFrame = CGRectMake(LabelFrame.size.width+4, 0, 50,
LabelFrame.size.height);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = buttonFrame;
[button setImage:[UIImage imageNamed:@"arrow.png"]
forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"arrow_open.png"]
forState:UIControlStateSelected];
[button addTarget:self action:@selector(discButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
self.discButton = button;
// static NSMutableArray *colors = nil;
// if (colors == nil) {
// colors = [[NSMutableArray alloc] initWithCapacity:3];
// UIColor *color = nil;
// color = [UIColor colorWithRed:0.61 green:0.74 blue:0.78
alpha:1];
// [colors addObject:(id)[color CGColor]];
// color = [UIColor colorWithRed:0.50 green:0.54 blue:0.58
alpha:1];
// [colors addObject:(id)[color CGColor]];
// color = [UIColor colorWithRed:0.15 green:0.20 blue:0.23
alpha:1];
// [colors addObject:(id)[color CGColor]];
// }
//[(CAGradientLayer *)self.layer setColors:colors];
//Singleton Obj allocation
// singletonObj=[[Singleton alloc]init];
singletonObj=[Singleton sharedDelegate];
if ([singletonObj.tempChangelistColor isEqualToString:@"red"]) {
self.layer.contents = (id)[UIImage
imageNamed:@"red.png"].CGImage;
}else if([singletonObj.tempChangelistColor
isEqualToString:@"yellow"]){
self.layer.contents = (id)[UIImage
imageNamed:@"yellow.png"].CGImage;
}else if([singletonObj.tempChangelistColor
isEqualToString:@"green"]){
self.layer.contents = (id)[UIImage
imageNamed:@"green.png"].CGImage;
}else{
self.layer.contents = (id)[UIImage
imageNamed:@"btn.png"].CGImage;
}
[(CAGradientLayer *)self.layer setLocations:[NSArray
arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber
numberWithFloat:0.48], [NSNumber numberWithFloat:1.0], nil]];
}
return self;
}
Now if you notice at the bottom of the implementation file there is an
image called btn.png and if I change that image then it changes all the
section views with that image. How do I change these individually and
assign images to these section views? Look at the arguments this method
handles and I'm thinking that isn't a UITableView.
No comments:
Post a Comment