我的部分代码:
commentTextView = [[GCPlaceholderTextView alloc] initWithFrame:CGRectMake(5.0f, 0.0f, 260.0f, 24.0f)];
[commentTextView setBackgroundColor:[UIColor clearColor]];
[commentTextView setTextColor:[UIColor whiteColor]];
[[commentTextView layer] setCornerRadius:2.0f];
[[commentTextView layer] setMasksToBounds:YES];
[commentTextView setDelegate:self];
[commentTextView setPlaceholder:NSLocalizedString(@"Add a comment ... ", nil)];//Add a comment is not showing and I dont know why.
[commentTextView setPlaceholderColor:[UIColor whiteColor]];
[commentTextView setTintColor:[UIColor colorWithRed:0.243 green:0.847 blue:0.769 alpha:1]];
[commentTextView setAutocorrectionType:UITextAutocorrectionTypeNo];
[inputAccessoryContentView addSubview:commentTextView];
我使用一个navigationcontroller作为我的rootcontroller。但是如果我使用viewcontroller作为我的rootcontroller,那个占位符效果很好。而GCPlaceholerTextView是一个UITextView。
这是我AppDelegate的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// works well in VC
/*
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc]init];
self.window.rootViewController = self.viewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
*/
// doesn't work well in nav
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}