求用纯代码做界面的源代码

tyoutk13520 2010-09-01 01:55:24
如题。
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiao4623581 2010-09-02
  • 打赏
  • 举报
回复
路过,看看
tyoutk13520 2010-09-02
  • 打赏
  • 举报
回复
这个问题就这么关掉了,想来不会又什么问题。

其实我更想要一整个工程,这样我可以顺便学习一下结构。iphone的例子大多都是用IB做的,没什么可以参考。
tyoutk13520 2010-09-01
  • 打赏
  • 举报
回复
谢谢你的回答。

我现在要忙着调查UIWebView的缓存,等我有时间再确认下。
云瑀 2010-09-01
  • 打赏
  • 举报
回复

#import <UIKit/UIKit.h>
@class UITextView;

@interface HelloController : UIViewController <UITabBarDelegate>
{
int value;
}
@end

@implementation HelloController

- (id)init
{
if (self = [super init])
{
self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
}
return self;
}

- (void) goRed
{
self.view.backgroundColor = [UIColor colorWithRed: 1.0f green:0.45f blue:0.45f alpha:1.0f];
}

- (void) goBlue
{
self.view.backgroundColor = [UIColor colorWithRed: 0.45f green:0.45f blue:1.0f alpha:1.0f];
}

- (void)loadView
{
// Set up the text view to show the current value
UITextView *contentView = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

contentView.editable = NO;
contentView.textAlignment = UITextAlignmentCenter;
contentView.font = [UIFont fontWithName:@"American Typewriter" size:120];

contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

self.view = contentView;
[contentView release];

// Initialize at 50
[(UITextView *)self.view setText:@"\n50"];
value = 50;

// The app style is black
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:4];

UIBarButtonItem *flexibleSpaceItem;
flexibleSpaceItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:NULL] autorelease];
[buttons addObject:flexibleSpaceItem];
[flexibleSpaceItem release];

UIBarButtonItem *item;
item = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"down.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(decrement:)];
[buttons addObject:item];
[item release];

item = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"up.png"]
style:UIBarButtonItemStylePlain target:self
action:@selector(increment:)];
[buttons addObject:item];
[item release];

flexibleSpaceItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:NULL] autorelease];
[buttons addObject:flexibleSpaceItem];
[flexibleSpaceItem release];

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlackOpaque;
[toolbar setItems:buttons animated:YES];
[toolbar sizeToFit];

self.navigationItem.titleView = toolbar;
[toolbar release];

// Add a left button
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Red"
style:UIBarButtonItemStylePlain
target:self
action:@selector(goRed)] autorelease];

// Add a right button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"Blue"
style:UIBarButtonItemStylePlain
target:self
action:@selector(goBlue)] autorelease];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

-(void) increment: (id) sender
{
[(UITextView *)self.view setText:[NSString stringWithFormat:@"\n%d", ++value]];
}

-(void) decrement: (id) sender
{
[(UITextView *)self.view setText:[NSString stringWithFormat:@"\n%d", --value]];
}
@end


@interface SampleAppDelegate : NSObject <UIApplicationDelegate>
@end
@implementation SampleAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[HelloController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
@end

int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"SampleAppDelegate");
[pool release];
return retVal;
}

这种的?

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧