|
|
|
iOS/Objective-C : Now Day Calendar working perfect. I will share my code. |
|
|
|
|
|
|
|
Now Day Calendar working perfect. I will share my code.
.h file
Code (Objective-C)
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
UIImageView *_topBackground;
UIButton *_leftArrow, *_rightArrow;
UILabel *_dateLabel;
NSDate *day1;
}
@end
.m file
Code (Objective-C)
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h> /* CALayer */
#import "next.h"
static NSString *LEFT_ARROW_IMAGE = @"ma_leftArrow.png";
static NSString *RIGHT_ARROW_IMAGE = @"ma_rightArrow.png";
static const unsigned int ARROW_LEFT = 100;
static const unsigned int ARROW_RIGHT = 101;
static const unsigned int ARROW_WIDTH = 48;
static const unsigned int ARROW_HEIGHT = 38;
static const unsigned int TOP_BACKGROUND_HEIGHT = 95;
#define CURRENT_CALENDAR [NSCalendar currentCalendar]
#define DATE_COMPONENTS (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit)
@interface ViewController()
- (void)changeDay:(UIButton *)sender;
- (NSDate *)nextDayFromDate:(NSDate *)date;
- (NSDate *)previousDayFromDate:(NSDate *)date;
@property (readonly) UIButton *leftArrow;
@property (readonly) UIButton *rightArrow;
@property (readonly) UILabel *dateLabel;
@property (readonly) UIFont *regularFont;
@property (readonly) UIFont *boldFont;
@property (readonly) NSString *titleText;
@end
@implementation ViewController
- (UIButton *)leftArrow {
if (!_leftArrow) {
_leftArrow = [UIButton buttonWithType:UIButtonTypeCustom];
_leftArrow.tag = ARROW_LEFT;
[_leftArrow setImage:[UIImage imageNamed:LEFT_ARROW_IMAGE] forState:0];
[_leftArrow addTarget:self action:@selector(changeDay:) forControlEvents:UIControlEventTouchUpInside];
}
return _leftArrow;
}
- (UIButton *)rightArrow {
if (!_rightArrow) {
_rightArrow = [UIButton buttonWithType:UIButtonTypeCustom];
_rightArrow.tag = ARROW_RIGHT;
[_rightArrow setImage:[UIImage imageNamed:RIGHT_ARROW_IMAGE] forState:0];
[_rightArrow addTarget:self action:@selector(changeDay:) forControlEvents:UIControlEventTouchUpInside];
}
return _rightArrow;
}
- (UILabel *)dateLabel {
if (!_dateLabel) {
_dateLabel = [[UILabel alloc] init];
_dateLabel.textAlignment = NSTextAlignmentCenter;
_dateLabel.backgroundColor = [UIColor clearColor];
_dateLabel.font = [UIFont boldSystemFontOfSize:18];
_dateLabel.textColor = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];
}
return _dateLabel;
}
- (void)setDay:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
day1 = [CURRENT_CALENDAR dateFromComponents:components];
[day1 copy];
self.dateLabel.text = [self titleText];
}
- (void)changeDay:(UIButton *)sender {
if (ARROW_LEFT == sender.tag) {
self.day = [self previousDayFromDate:day1];
} else if (ARROW_RIGHT == sender.tag) {
self.day = [self nextDayFromDate:day1];
}
}
- (NSDate *)nextDayFromDate:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
[components setDay:[components day] + 1];
return [CURRENT_CALENDAR dateFromComponents:components];
}
- (NSDate *)previousDayFromDate:(NSDate *)date {
NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date];
[components setDay:[components day] - 1];
return [CURRENT_CALENDAR dateFromComponents:components];
}
- (NSString *)titleText {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
return [NSString stringWithFormat:@"%@",
[formatter stringFromDate:day1]];
}
- (void)viewDidLoad
{
self.rightArrow.frame = CGRectMake(280, 60, 20, 20);
[self.view addSubview:_rightArrow];
self.leftArrow.frame = CGRectMake(10, 60, 20, 20);
[self.view addSubview:_leftArrow];
self.day = [NSDate date];
[self.view addSubview:_dateLabel];
self.dateLabel.frame = CGRectMake(60, 0, 200, 150);
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
need this two images
Tag : Mobile, iOS, iPhone, Objective-C
|
|
|
|
|
|
Date :
2013-08-20 14:41:28 |
By :
vishwa |
View :
1250 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Oh.. good.. sathish
|
|
|
|
|
Date :
2013-08-20 17:52:11 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thanks mr.win
|
|
|
|
|
Date :
2013-08-20 19:01:40 |
By :
vishwa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|