-1

That's the code: TheViewer.h

//
//  TheViewer.h
//  The Writer
//
//  Created by Imac on 17/11/13.
//  Copyright (c) 2013 Imac. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface TheViewer : NSObject
{

    IBOutlet NSTextField *textField;
    IBOutlet NSTextField *viewer;
    IBOutlet NSColor *textColor;
    IBOutlet NSColorWell *well;
    IBOutlet NSPopUpButton *popup;

}

- (IBAction)sendText:(id)sender;
- (IBAction)deleteText:(id)sender;
- (IBAction)settingColor:(id)sender;


@end

and here TheViewer.m

//
//  TheViewer.m
//  The Writer
//
//  Created by Imac on 17/11/13.
//  Copyright (c) 2013 Imac. All rights reserved.
//

#import "TheViewer.h"

@implementation TheViewer


- (IBAction)sendText:(id)sender
{

    NSString *testo = [textField stringValue];
    [viewer setStringValue:testo];
    NSString *theItem = [NSString stringWithFormat:@"",[popup titleOfSelectedItem]];

    if([theItem isEqualToString:@"Red"])
    {
        [viewer setTextColor:[NSColor redColor]];
    }
    if([theItem isEqualToString:@"Blue"])
    {
        [viewer setTextColor:[NSColor redColor]];
    }

    if([theItem isEqualToString:@"Yellow"])
    {
        [viewer setTextColor:[NSColor redColor]];
    }


}

- (IBAction)deleteText:(id)sender
{
    [viewer setStringValue:@""];
}

- (IBAction)settingColor:(id)sender
{
    [viewer setTextColor:sender];
}

@end

it should color the text with the color choosed from the user but... it doesn't work! Can someone tell me why?

I also tried with the colorweel but I didn't managed to understand how does it works. I know, I know, I'm just a noob.

Peter Foti
  • 5,526
  • 6
  • 34
  • 47
  • 2
    try UIColor instead of NSColor – 4GetFullOf Nov 18 '13 at 14:24
  • Question is about OSX, so NSColor is correct here. – Vytautas Nov 18 '13 at 15:01
  • did you try to redraw the view / window? check out setNeedsDisplay property for NSView, when the setting of color seems to be impossible try setting the attributedStringValue /attributedTitle, depends on a control. check out this: http://stackoverflow.com/questions/13109964/nsbutton-how-to-color-the-text – nio Nov 18 '13 at 15:06

1 Answers1

3

I believe your problem is here:

 NSString *theItem = [NSString stringWithFormat:@"",[popup titleOfSelectedItem]];

Change it to:

 NSString *theItem = [NSString stringWithFormat:@"%@",[popup titleOfSelectedItem]];

You have forgot to type %@, and because of that none of if's matches.

Vytautas
  • 573
  • 3
  • 8