【发布时间】:2013-04-11 01:42:19
【问题描述】:
这可能是一个简单的问题,但我无法弄清楚我错过了什么。
在 ViewControl.h 中我声明了 UIColor
@property (nonatomic, strong) UIColor * myColor;
在 ViewControl.m 中,我有一个方法可以执行某些操作并返回新的 UIColor
@synthesize myColor = _myColor;
在 ViewDidLoad 方法中
- (void)viewDidLoad
{
myColor = [UIColor RedColor];
}
-(void) ShowColorPopUpView
{
if (!self.wePopoverController)
{
ColorViewController *contentViewController = [[ColorViewController alloc] init];
contentViewController.delegate = self;
self.wePopoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
self.wePopoverController.delegate = self;
self.wePopoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];
[self.wePopoverController presentPopoverFromRect:self.tvTweetDetails.frame
inView:self.view
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown)
animated:YES];
} else
{
[self.wePopoverController dismissPopoverAnimated:YES];
self.wePopoverController = nil;
}
}
-(void) colorPopoverControllerDidSelectColor:(NSString *)hexColor
{
_myColor = [GzColors colorFromHex:hexColor];
[self.view setNeedsDisplay];
[self.wePopoverController dismissPopoverAnimated:YES];
self.wePopoverController = nil;
}
- (UIColor *) returnColor
{
return _myColor;
}
我的问题从这里开始:我有两种方法可以更改 textview 字体和背景颜色
- (IBAction)btnFontColorPopUpMenu:(id)sender
{
[self ShowColorPopUpView];
tvTweetDetails.textColor = [self returnColor];
}
- (IBAction)btnTextViewBackGroundColor:(id)sender
{
[self ShowColorPopUpView];
tvTweetDetails.backgroundColor = [self returnColor];
}
现在的问题是,当我调用它返回的方法时,它会返回 RED,如果我再次调用它,它会返回 BlackColor。
如何调用该方法并将颜色更改为新颜色,然后将其返回。我想直接得到黑色。
我想先执行该方法然后返回颜色,但发生的情况是在执行该方法之前分配颜色。
我希望我把问题说清楚了。
【问题讨论】:
-
在
changeMycolor方法中添加myColor = [UIColor RedColor];。 -
你到底想在这里做什么?
-
它已经添加了......对不起,我想写 myColor 而不是 myString。 @AnoopVaidya
-
@bdesham 好的,这个 changeMyColor 实际上是一个返回颜色的颜色选择器方法。因此,每当我想更改 TextView 背景或文本颜色时,我都会调用此方法。问题是当我调用它时,它会返回之前选择的颜色
-
我认为您应该展示您如何在该方法中更改颜色
标签: iphone ios objective-c xcode