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;
}
i want to display multiple images in a view controller using iCarousel.
i list all my images in NSMutableArray foto,
and then i called the array foto in iCarousel method viewForItemAtIndex.
i've followed some tutorial but still doesn't work.
please help me.
here's my .m code
#import "TestController.h"
#interface TestController () <UIActionSheetDelegate>
#property (nonatomic, retain) NSMutableArray *foto;
#end
#implementation TestController
#synthesize carousel;
#synthesize foto;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Seleb1.jpg"],
[UIImage imageNamed:#"Seleb2.jpg"],
[UIImage imageNamed:#"Seleb3.jpg"],
nil];
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];
return view;
}
#end
can someone help me ?
what is wrong with my code ?
Updated Code
#import "TestController.h"
#interface TestController ()
#property (nonatomic, retain) NSArray *foto;
#end
#implementation TestController
#synthesize carousel;
#synthesize foto;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
#"Seleb1.jpg",
#"Seleb2.jpg",
#"Seleb3.jpg",
nil];
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image
UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
return value+0.1;
}
#end
change this line
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];
to
Reason : you have already defined your array as [UIImage imageNamed:#"Seleb1.jpg"] , so in here you need call directly like
view = [[UIImageView alloc] initWithImage:[foto objectAtIndex:index]];
Choice-2
create a array like
foto = [NSArray arrayWithObjects:
#"Seleb1.jpg",
#"Seleb2.jpg",
#"Seleb3.jpg",
nil];
and call like
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];
if you need
use this
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}
Update answer
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image
UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;
return view;
}
#TomKnapen : where should i set it ? if it's on the story board, i've
set it already. in the TestController.h, i've set it too here's my
code in .h : TestController : UIViewController – Shasapo
I'm not sure about how you are setting it in storyboard, but in code, you are not setting the delegate. This line doesn't set the delegate TestController : UIViewController <iCarouselDataSource,iCarouselDelegate>, what it does is it makes you controller, which is TestController in this case, comply to the iCarouselDelegate protocol. What you have to do is explicitly set the delegate and datasource in viewDidLoad,for example, i.e.
carousel.delegate = self;
carousel.datasource = self;
2 - try debugging those delegate methods first. Start with nimberOfItems method, check if foto array isnt nil. Then in viewForItem method check if the image that you return isn't nil.
Because you are using storyboard, your initWithNibName method not getting called, that is why you foto array not getting initialized, I assume. In my opinion your numberofitems method returns 0. Try to put breakpoint int this method and see, or just add a NSLog statement and check if foto array isnt nil
3 - You are not adding iCarousel view to your view.
I have used this framework in the past, so I decided to include a snippet of the code I implemented
#pragma mark -
#pragma mark iCarousel methods
- (void)iCarouselSetup {
self.view.backgroundColor = kAppColor;
self.carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, calendarBar.bottom + 10, self.view.width, self.view.height)];
[self.view addSubview:self.carousel];
self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeCoverFlow;
self.carousel.scrollEnabled = NO;
[self.carousel scrollToItemAtIndex:2 animated:NO];
self.currentProjectsTableview = (UITableView*)[self.carousel currentItemView]; }
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return 5; }
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
self.projectsTableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
self.projectsTableview.x = 0;
self.projectsTableview.y = calendarBar.bottom;
self.projectsTableview.width = [ASize screenWidth];
self.projectsTableview.height = [ASize screenHeight] - 180;
self.projectsTableview.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
self.projectsTableview.backgroundColor = [UIColor fromRGB:0xF8F8F8];
self.projectsTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
self.projectsTableview.dataSource = self;
self.projectsTableview.delegate = self;
self.projectsTableview.tag = tableTag++;
return self.projectsTableview; }
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
self.carousel.scrollEnabled = NO;
[AppDelegate getDelegate].deckController.panningMode = IIViewDeckFullViewPanning;
[UIView animateWithDuration:0.3 animations:^{
for (int i = 0; i < self.carousel.numberOfItems; i++)
{
[self.carousel itemViewAtIndex:i].transform = CGAffineTransformMakeScale( 1.1f, 1.1f);
}
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
for (int i = 0; i < self.carousel.numberOfItems; i++)
{
[self.carousel itemViewAtIndex:i].transform = CGAffineTransformMakeScale( 1.0f, 1.0f);
[self.carousel itemViewAtIndex:i].userInteractionEnabled = YES;
}
} ];
tableMinimized = NO;
}];
self.currentProjectsTableview = (UITableView*)[carousel itemViewAtIndex:index]; }
- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel {
[navButton setTitle:self.projectDates[self.carousel.currentItemIndex] forState:UIControlStateNormal]; }
i fix my code by combining all your answer, thankyou so much. here's my new code :
#import "TestController.h"
#interface TestController ()
#property (nonatomic, retain) NSArray *foto;
#end
#implementation TestController
#synthesize carousel;
#synthesize foto;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
carousel.delegate = self;
carousel.dataSource = self;
foto = [NSArray arrayWithObjects:
#"Seleb1.jpg",
#"Seleb2.jpg",
#"Seleb3.jpg",
nil];
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
NSLog(#"%lu",(unsigned long)foto.count);
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image
UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
return value+0.1;
}
#end
Thank you so much for all your answer, i really appreciate it :)
I created MyCustomView which has two labels. One at left and one with right align and at right. It has about 30px height (it's not important). I connect it to xib and it works. In .xib I set main view width to 400px and set autolayout constraints for labels.
Now the problem. When I added to my controller in IB with UIView and set class to MyCustomView I see left label but right label is out of screen. I set constraints right but It doesn't work. When I tried to resize MyCustomView in .xib by mouse and moving with edges it's okay but when I set width value "manually" in right column it doesn't layout right (it doesn't change at all). Where is the problem? How can I fix this?
#implementation MyCustomView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}
- (void)commonInit
{
self.backgroundColor = [UIColor clearColor];
self.view = [[[NSBundle mainBundle] loadNibNamed:#"MyCustomView"
owner:self
options:nil] firstObject];
[self addSubview:self.view];
//self.translatesAutoresizingMaskIntoConstraints = NO;
}
- (void)awakeFromNib {
[super awakeFromNib];
//[self setNeedsUpdateConstraints];
//[self setNeedsLayout];
}
#end
As you can see in comments I tried some ways but nothing helped.
New File --> iOS (Source) -- Cocoa Touch --> Next
Enter Name
Add code in MyCustomView.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//self.view.backgroundColor = [UIColor redColor];
self.preferredContentSize = CGSizeMake(30.0, 400.0);
}
return self;
}
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've created a gradient using Quartz, only one issue. I can't get it to rotate with the screen. I've tried everything listed on this tutorial. Here's the view controller header:
#import <UIKit/UIKit.h>
#interface RadialGradientBackgroundViewController : UIViewController {
}
#end
And here's the view controller:
#import "RadialGradientBackgroundViewController.h"
#import "BackgroundLayer.h"
#implementation RadialGradientBackgroundViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
CAGradientLayer *bgLayer = [BackgroundLayer gradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[[[self.subview.layer sublayers] objectAtIndex:0] setFrame:self.view.bounds]; // Error is here!
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
#end
Your view controller does not have a subview property or method. As rmaddy said, change subview to view.