iOS プロジェクトで各メイン ビューのタイトルを設定できるようにするには、どうすればよいですか。以下は、私がこれまでに得たものと、私がやろうとしていることです...
一緒に作業しようとしている作成済みファイル。
- PageTitleView.h
- PageTitleView.m
- PageBaseViewController.h
- PageBaseViewController.m
- HomeViewController.h
- HomeViewController.m
- ActivityFeedViewController.h
- ActivityFeedViewController.m
基本的に、PageTitleView.h * .m と PageBaseViewController.h & .m をセットアップして、HomeViewController&ActivityFeedViewController を呼び出し、現在のビューのタイトルを設定できるようにします。
これらのファイルからの私のコードは次のとおりです
PageTitleView.h
#import "ContainerView.h"
#import "BaseLabel.h"
@interface PageTitleView : ContainerView
@property (nonatomic, strong) BaseLabel* label;
@property (nonatomic, strong) NSString* title;
@end
PageTitleView.m
#import "PageTitleView.h"
@implementation PageTitleView
@synthesize label;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 35)];
label = [[BaseLabel alloc] initWithFrame:CGRectMake(18, 10, frame.size.width , 25)];
label.font=[UIFont fontWithName:@"Helvetica" size:15.0];
label.textColor = (UIColor *) COLOR_DARK_BLUE;
label.text =[[NSString alloc] initWithFormat: @"text"];
self.backgroundColor = (UIColor *)COLOR_WHITE;
self.layer.shadowOpacity = 0.05;
self.layer.shadowOffset = CGSizeMake(.25, .25);
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowRadius = 5;
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.layer.bounds].CGPath;
self.layer.cornerRadius = 10.0;
self.layer.borderWidth = 0.25;
self.layer.borderColor = [UIColor grayColor].CGColor;
[self addSubview:label];
return self;
}
@end
PageBaseViewController.h
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#import "Settings.h"
#import "CustomButton.h"
#import "PageTitleView.h"
@interface PageBaseViewController : UIViewController
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) CustomButton *backButton;
@end
PageBaseViewController.m
#import "PageBaseViewController.h"
@interface PageBaseViewController ()
@end
@implementation PageBaseViewController
synthesize scrollView;
- (void)viewDidLoad {
[super viewDidLoad];
// GRADIENT
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:
(id)BACKGROUND_GRADIENT_COLOR_1.CGColor,
(id)BACKGROUND_GRADIENT_COLOR_2.CGColor,
(id)BACKGROUND_GRADIENT_COLOR_3.CGColor, nil];
gradient.locations = [NSArray arrayWithObjects:
(id)[NSNumber numberWithFloat:0.0],
(id)[NSNumber numberWithFloat:0.4],
(id)[NSNumber numberWithFloat:1.0], nil];
[self.view.layer insertSublayer:gradient atIndex:0];
float height = self.view.frame.size.height - TITLEBAR_HEIGHT - self.tabBarController.tabBar.frame.size.height;
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, TITLEBAR_HEIGHT, self.view.frame.size.width, height)];
[self.view addSubview:scrollView];
PageTitleView *pageTitle = [[PageTitleView alloc] initWithFrame:CGRectMake(105, -10, 100 , 35)];
[self.view addSubview:pageTitle];
/* This button is currently added to the view and will show in the TITLEBAR_HEIGHT.
These will be used throughout the entire project, we will be working next to have
correct buttons turn on and off for each view.*/
CustomButton *buttonLeft = [[CustomButton alloc] initWithFrame:CGRectMake(5, 5, 60, 25) andText:@"Left"];
[buttonLeft addTarget:self action:@selector(buttonLeft:) forControlEvents:UIControlEventTouchUpInside];
[buttonLeft setBackgroundColor:BUTTON_COLOR_1];
[self.view addSubview:buttonLeft];
// Remove this button from homeview and have a logo show up.
CustomButton *buttonRight = [[CustomButton alloc] initWithFrame:CGRectMake(235, 5, 80, 25) andText:@"Right"];
[buttonRight addTarget:self action:@selector(buttonRight:) forControlEvents:UIControlEventTouchUpInside];
[buttonRight setBackgroundColor:BUTTON_COLOR_1];
[self.view addSubview:buttonRight];
}
- (void)buttonLeft:(UIButton *)buttonLeft {
NSLog(@"Ping");
}
- (void)buttonRight:(UIButton *)buttonRight {
NSLog(@"Ping");
}
@end