在Cocos2d中使用UITextView

UITextView

#define TEXTVIEW_WIDTH 400.0f
#define TEXTVIEW_HEIGHT 280.0f
#define TEXTVIEW_CENTER_X 240.0f
#define TEXTVIEW_CENTER_Y 160.0f

    // create a text view
    textView = [[UITextView alloc] initWithFrame: CGRectMake(-TEXTVIEW_WIDTH/2, -TEXTVIEW_HEIGHT/2, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT)];
    // set some properties of the text view
    [textView setEditable: NO]; // not editable
    [textView setHidden: YES]; // hidden
    [textView setTextColor: [UIColor blackColor]]; // set text color
    [textView setFont: [UIFont fontWithName: @"Helvetica-Bold" size: 20]]; // set font
    [textView setBackgroundColor: [UIColor whiteColor]]; // set background color
    [textView setText: @"Text\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText\nText"]; // set text
    [textView setScrollEnabled: YES]; // enable scroll
    [textView setUserInteractionEnabled: YES]; // enable user interaction
    [textView setShowsVerticalScrollIndicator: YES]; // show vertical scroll indicator
    [textView setTransform: CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI_2), TEXTVIEW_CENTER_X, -TEXTVIEW_CENTER_Y)]; // set transform
    // add the text view to the window
    [[[[CCDirector sharedDirector] openGLView] window] addSubview: textView];

posted on 2013-01-17 22:01  紫澜  阅读(380)  评论(0编辑  收藏  举报