фон прокрутки - PullRequest
       14

фон прокрутки

1 голос
/ 18 апреля 2009

в моем приложении я добавляю фон в UITextView. Но когда текстовое представление прокручивается вниз, изображение идет вместе с текстом, и фон для новых строк текста кажется белым. Есть ли простой способ справиться с этим? Вот мой код:

textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)];

UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(0, 0, 270, 130)];
imgView.image = [UIImage imageNamed: @"background.png"];
[textView addSubview: imgView];
[textView sendSubviewToBack: imgView];
[imgView release];


textView.opaque = YES;
textView.editable = YES;
textView.font = [UIFont systemFontOfSize: 12];
textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f];
textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
textView.delegate = self;

[mainScrollView addSubview: textView];

Я хочу, чтобы фон оставался статичным с прокруткой текста поверх него.

Ответы [ 2 ]

2 голосов
/ 18 апреля 2009

Если вы хотите, чтобы фон оставался статичным и имел текстовую прокрутку поверх него, просто добавьте UIImageView к тому же представлению, к которому вы добавляете UIScrollView (с теми же размерами и т. Д.). Что-то вроде:

UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(0, 0, 270, 130)];
imgView.image = [UIImage imageNamed: @"background.png"];
[self addSubView:imgView];
[imgView release];

textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)];

textView.opaque = YES;
textView.editable = YES;
textView.font = [UIFont systemFontOfSize: 12];
textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f];
textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
textView.delegate = self;
// Make the background of the textView transparent
textView.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];

[mainScrollView addSubview: textView];

Я предполагаю, что этот код выполняется в UIView, поэтому я добавляю оба UIImageView self. Если вы делаете это из UIViewController, вы можете изменить его на [self.view addSubView:mainScrollView].

0 голосов
/ 18 апреля 2009

Спасибо, ПГБ.

Этот код наконец работает для меня:

    UIImageView *imgView = [ [UIImageView alloc]initWithFrame: CGRectMake(10, 100, 270, 130)];
    imgView.image = [UIImage imageNamed: @"background.png"];
    [mainScrollView addSubview: imgView];
    [mainScrollView sendSubviewToBack: imgView];
    [imgView release];

    textView = [ [UITextView alloc] initWithFrame: CGRectMake(10, 100, 270, 130)];

    textView.opaque = YES;
    textView.editable = YES;
    textView.font = [UIFont systemFontOfSize: 12];
    textView.textColor = [UIColor colorWithRed: 10.0f/255.0f green: 10.0f/255.0f blue: 10.0f/255.0f alpha: 1.0f];
    textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textView.delegate = self;
    // Make the background of the textView transparent
    textView.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0];

    [mainScrollView addSubview: textView];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...