3 つの UILabel Textfields があり、それぞれの値を比較して、最小値を強調表示しようとしています。
現在、次のコードがあります。
if (((pd1 <= pd3) && (pd1 <= pd2)) || ((pd2 == 0) && (pd3 == 0))){
pdOne.textColor = [UIColor yellowColor];
}
if (((pd2 > 0) && (pd2 <= pd1)) && ((pd3 >0) && (pd2 <= pd3))) {
pdTwo.textColor = [UIColor yellowColor];
}
if ((pd3 >0) && (pd3 <=1) && (pd3 <= pd2)) {
pdThree.textColor = [UIColor yellowColor];
}
どこかで私は非常に間違っているので、これについて少しガイダンスが欲しいです。
どうもありがとう
アクションの完全なコードは
- (IBAction)calculateOne:(id)sender; {
NSLog(@"count=%d",count);
pd3 = pd2;
pdThree.text = pdTwo.text;
pdThree.font = [UIFont systemFontOfSize:kDefaultFontSize];
//setup text resizing check here
if (pdThree.contentSize.height > pdThree.frame.size.height) {
int fontIncrement = 1;
while (pdThree.contentSize.height > pdThree.frame.size.height) {
pdThree.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
fontIncrement++;
}
}
pd2 = pd1;
pdTwo.text = pdOne.text;
pdTwo.font = [UIFont systemFontOfSize:kDefaultFontSize];
//setup text resizing check here
if (pdTwo.contentSize.height > pdTwo.frame.size.height) {
int fontIncrement = 1;
while (pdTwo.contentSize.height > pdTwo.frame.size.height) {
pdTwo.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
fontIncrement++;
}
}
[brand resignFirstResponder];
[qty resignFirstResponder];
[size resignFirstResponder];
[price resignFirstResponder];
double num1, num2, num3, num4, answerb;
num1 = [qty.text intValue];
num2 = [size.text intValue];
num3 = [price.text intValue];
num4 = (num3/100);
count = (count+1);
NSLog(@"count=%d",count);
answerb=((num3/(num1*num2))*10);
pd1 = answerb;
NSString *answerStringc = [[NSString alloc] initWithFormat:@"%@ %@ x %@ml @ £%.2f = £%.4f/litre ", brand.text, qty.text, size.text, num4, answerb];
pdOne.text= answerStringc;
pdOne.font = [UIFont systemFontOfSize:kDefaultFontSize];
pdOne.textColor = [UIColor whiteColor];
pdTwo.textColor = [UIColor whiteColor];
pdThree.textColor = [UIColor whiteColor];
if (((pd1 <= pd3) && (pd1 <= pd2)) || ((pd2 == 0) && (pd3 == 0))){
pdOne.textColor = [UIColor yellowColor];
}
if (((pd2 > 0) && (pd2 <= pd1)) && ((pd3 >0) && (pd2 <= pd3))) {
pdTwo.textColor = [UIColor yellowColor];
}
if ((pd3 >0) && (pd3 <=pd1) && (pd3 <= pd2)) {
pdThree.textColor = [UIColor yellowColor];
}
//setup text resizing check here
if (pdOne.contentSize.height > pdOne.frame.size.height) {
int fontIncrement = 1;
while (pdOne.contentSize.height > pdOne.frame.size.height) {
pdOne.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
fontIncrement++;
}
}
NSLog(@"pd1 = %f",pd1);
NSLog(@"pd2 = %f",pd2);
if ((count >1) && ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) && ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])) {
self.tweetButton.enabled = YES;
self.tweetButton.alpha = 1.0f;
self.facebookButton.enabled = YES;
self.facebookButton.alpha = 1.0f;
} else if ((count <2)) {
self.tweetButton.enabled = NO;
self.tweetButton.alpha = 0.5f;
self.facebookButton.enabled = NO;
self.facebookButton.alpha = 0.5f;
}
}