Hello
I have a view that i'd like to put inside a uiscrollview and the uiscrollview in a uitabcontroller but i'm missing something.
Can anyone help me here please? i have searched the documentation buti can't figure how to do this programaticly. using a xib i have no problems..
my code:
appdelegate.h
Code:
#import <UIKit/UIKit.h>
#import "area1.h"
#import "area2.h"
@interface subviewsAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UIWindow *window;
@end
appdelegate.m:
Code:
@implementation subviewsAppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[[self window] setRootViewController:tabBarController];
NSMutableArray *x = [NSMutableArray array];
[x addObject: [[[area1 alloc] init] autorelease]];
[x addObject: [[[area2 alloc] init] autorelease]];
[tabBarController setViewControllers:x];
[tabBarController release];
[[self window] makeKeyAndVisible];
return YES;
}
area2.h
Code:
#import <UIKit/UIKit.h>
#import "imageScrollProgramaticamente.h"
@interface area2 : UIViewController
{
UIScrollView* scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@end
area2.m
Code:
#import "area2.h"
@implementation area2
@synthesize scrollView;
- (id)init
{
if(self = [super init])
{
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@"area2"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
imageScrollProgramaticamente *isp = [[imageScrollProgramaticamente alloc] initWithFrame:CGRectZero];
[self setView:isp];
[isp setBackgroundColor:[UIColor orangeColor]];
[isp release];
}
imagescrollprogramaticamente.h
Code:
#import <UIKit/UIKit.h>
@interface imageScrollProgramaticamente : UIScrollView{
}
imageprogramaticamente.m
Code:
#import "imageScrollProgramaticamente.h"
@implementation imageScrollProgramaticamente
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//what rectangle am i filling?
CGRect bounds = [self bounds];
//where is the center?
CGPoint center;
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height /2.0;
//from the center how far out of a corner?
//float maxRadius = hypotf(bounds.size.width, bounds.size.height) /2.0;
//create a string
NSString *text = @"apple";
//get a font to draw it in
UIFont * font = [UIFont boldSystemFontOfSize:200];
//where am i going to draw it?
CGRect textRect;
textRect.size = [text sizeWithFont:font];
textRect.origin.x = center.x - textRect.size.width / 2.0;
textRect.origin.y = center.y - textRect.size.height / 2.0;
//set the fill color of the current context to black
[[UIColor blackColor] setFill];
//draw the string
[text drawInRect:textRect withFont:font];
}
@end
now... how can i make this imagescrollprogramaticamente...scroll?
Regards