Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Wednesday, 26 June 2013

How to create SegmentedControlButton to change color of textfield-text in Xcode

 Here, we will teach you how to make a segmented control button with 3 segments, and how it can be used for changing color of text in an UITextfield.




in .h:

        @interface ViewController : UIViewController{
            IBOutlet UISegmentedControl *colorChooser;
            IBOutlet UITextView *sampleText;
        }
        @property(nonatomic, retain) UISegmentedControl *colorChooser;
        @property(nonatomic, retain) UITextView *sampleText;

        -(IBAction)colorChanged;
        @end

in .m:

        @implementation ViewController

        @synthesize colorChooser,sampleText;

        -(IBAction)colorChanged{
            if (colorChooser.selectedSegmentIndex==0)sampleText.textColor= [UIColor blackColor];
            if (colorChooser.selectedSegmentIndex==1)sampleText.textColor= [UIColor blueColor];
            if (colorChooser.selectedSegmentIndex==2)sampleText.textColor= [UIColor redColor];
   
        }
in xib:
 
  • Drag and drop a segmented control view, and make it a 3 segmented one.
  • Drag and drop a text view
  • From "Connections inspector-window", connect:
                          Segmented Control : Value Changed            ---->colorChanged
                          Segmented Control : New referencing outlet ---->colorChooser
                          TextView          : New referencing outlet       ---->sampleText 



Now Build and Run the application. You can see the text field and 3 segmented button. Click on each segment and see the change in color of the textfield text.

 

Sunday, 2 June 2013

How to create UITextField programmatically: cocos2d/Xcode

In .h file:

        @interface SceneName : CCLayer <UITextFieldDelegate>
       
            UITextField *nameField;

In .m file:

   // To create UITextField and assigning properties//

        -(void)createTextField{
           // create a UIView here(say profileView). Then do the following code //

            nameField = [[UITextField alloc] initWithFrame:CGRectMake(5, 20, 150, 30)];
            nameField.center = CGPointMake(285, 120);
            nameField.backgroundColor = [UIColor whiteColor];
            nameField.textAlignment = UITextAlignmentCenter;
            nameField.delegate = self;
            [nameField.layer setBorderColor:[[UIColor redColor]CGColor]];
            [nameField.layer setBorderWidth:1];
            nameField.layer.cornerRadius = 8;
            nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            [nameField addTarget:self action:@selector(valueChanged)
                                   forControlEvents:UIControlEventEditingChanged];
            [profileView addSubview:nameField];
        }

  
   // To resign first responder/keyboard //
   
        -(BOOL)textFieldShouldReturn:(UITextField *)textField
            {
                [textField resignFirstResponder];
                NSLog(@"%@ ",textField.text);                       // To get/print the data from the TextField
                return YES;
            }

        -(void)valueChanged{
            // To Limit text field text length //
            if ([nameField.text length] > 12) {
                nameField.text = [nameField.text substringToIndex:12];
            }
        }

    /*---------Some other important UITextField delegates---------*/
    -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
        return YES;
    }

    - (BOOL) textFieldShouldBeginEditing:(UITextField *)textField{
        return YES;
    }

    - (void) textFieldDidBeginEditing:(UITextField *)textField
    {
   
    }
  

Thursday, 30 May 2013

How to mark deleted and inserted text: HTML

We can mark/show a text as deleted with a strike across it, and newly inserted text with a selection. It can be done in HTML with the help of following tags.

Sample:

      <p>My favorite color is <del>blue</del> <ins>red.</ins>


Output:

     My favorite color is blue red.

Wednesday, 29 May 2013

HTML Text formattings

Heading formatting:
  1. <h1> Largest sized heading <h1>
  2. <h2> Smaller than h1 <h2>
  3. <h3> Smaller than h2 <h3>
  4. <h4> Smaller than h3 <h4>
  5. <h5> Smaller than h4 <h5>
  6. <h6> Smaller than h5, and the smallest heading <h6>
Paragraph formatting:
  1.  <b>         Used for bold text              </b>
  2.  <strong> Used for strong text          </strong>
  3. <big>       Used for big text                </big>
  4. <em>       Used for emphasized text  </em>
  5. <i>           Used for italic text               </i>
  6. <small>    Used for small text               </small>
  7. This is used for <sub>subscript</sub> and this is for <sup>superscript</sup>