iphone – UISegmentedControl文本多行?

iphone – UISegmentedControl文本多行?,第1张

概述如何使UISegmentedControl中的其中一个按钮的文本跨多行? 我这样做: >创建一个多线UILabel >用N行文本填写标签 >将标签转换成UIImage >将图像设置为片段内容 这在iOS 4,5,6上顺利 和iOS 7(只是删除文字阴影) MultiLineSegmentedControl – 头文件 //// MultiLineSegmentedControl.h//// 如何使UISegmentedControl中的其中一个按钮的文本跨多行?解决方法 我这样做:

>创建一个多线UILabel
>用N行文本填写标签
>将标签转换成UIImage
>将图像设置为片段内容

这在iOS 4,5,6上顺利

和iOS 7(只是删除文字阴影)

MultilinesegmentedControl – 头文件

////  MultilinesegmentedControl.h////  Created by Jens KreIEnsIEk on 20.07.11.//  copyright 2011 SoButz. All rights reserved.//#import <Foundation/Foundation.h>@interface MultilinesegmentedControl : UISegmentedControl- (voID)setMultilineTitle:(Nsstring *)Title forSegmentAtIndex:(NSUInteger)segment;@end

MultilinesegmentedControl – 实现文件

////  MultilinesegmentedControl.m////  Created by Jens KreIEnsIEk on 20.07.11.//  copyright 2011 SoButz. All rights reserved.//#import "MultilinesegmentedControl.h"#import "UIVIEw+LayerShot.h"@interface MultilinesegmentedControl()@property (nonatomic,retain) UILabel *theLabel;@end@implementation MultilinesegmentedControl@synthesize theLabel;- (voID)dealloc{    self.theLabel = nil;    [super dealloc];}- (UILabel *)theLabel{    if (!self->theLabel) {        self->theLabel = [[UILabel alloc] initWithFrame:CGRectZero];        self->theLabel.textcolor = [UIcolor whitecolor];        self->theLabel.backgroundcolor = [UIcolor clearcolor];        self->theLabel.Font = [UIFont boldSystemFontOfSize:13];        self->theLabel.textAlignment = UITextAlignmentCenter;        self->theLabel.lineBreakMode = UIlineBreakModeWorDWrap;        self->theLabel.shadowcolor = [UIcolor darkGraycolor];        self->theLabel.numberOflines = 0;    }    return self->theLabel;}- (voID)setMultilineTitle:(Nsstring *)Title forSegmentAtIndex:(NSUInteger)segment{    self.theLabel.text = Title;    [self.theLabel sizetoFit];    [self setimage:self.theLabel.imageFromLayer forSegmentAtIndex:segment];}@end

UIVIEw LayerShot – 头文件

////  UIVIEw+LayerShot.h////  Created by Jens KreIEnsIEk on 29.06.12.//  copyright (c) 2012 SoButz. All rights reserved.//#import <UIKit/UIKit.h>@interface UIVIEw (LayerShot)- (UIImage *)imageFromLayer;@end

UIVIEw LayerShot – 实现文件

////  UIVIEw+LayerShot.m////  Created by Jens KreIEnsIEk on 29.06.12.//  copyright (c) 2012 SoButz. All rights reserved.//#import "UIVIEw+LayerShot.h"#import <QuartzCore/QuartzCore.h>@implementation UIVIEw (LayerShot)- (UIImage *)imageFromLayer{    UIGraphicsBeginImageContextWithOptions(self.bounds.size,NO,0);    [self.layer renderInContext:UIGraphicsGetCurrentContext()];    UIImage *image = UIGraphicsGetimageFromCurrentimageContext();    UIGraphicsEndImageContext();    return image;}@end

像普通的UISegmentedControl一样使用它:

...MultilinesegmentedControl *segment = [[MultilinesegmentedControl alloc]     initWithItems:[NSArray arrayWithObjects:@"A",@"B",nil]];segment.segmentedControlStyle = UISegmentedControlStylebar;segment.frame = CGRectMake(0,200,segment.frame.size.height * 1.5);[segment setMultilineTitle:@"Title A\nSubTitle A" forSegmentAtIndex:0];[segment setMultilineTitle:@"Title B\nSubTitle B" forSegmentAtIndex:1];[self.vIEw addSubvIEw:segment];[segment release];...
总结

以上是内存溢出为你收集整理的iphone – UISegmentedControl文本多行?全部内容,希望文章能够帮你解决iphone – UISegmentedControl文本多行?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073198.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存