awakefromnib有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

awakefromnib  时间:2021-07-05  阅读:()

如何在UITextView中添加默认文字

在UITextField中自带placeholder属性,可以用于提示输入框信息。

但是UITextView并不具备此功能 介绍两种方法来实现: 第一种: 初始化UITextView //首先定义UITextView UITextView *textView = [[UITextView alloc] init]; textView.font = [UIFont systemFontOfSize:14]; textView.frame =CGRectMake(10, 0, cell.contentView.bounds.size.width-20, side); textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; textView.backgroundColor = [UIColor whiteColor]; [cell.contentView addSubview:textView]; textView.hidden = NO; textView.delegate = self; //其次在UITextView上面覆盖个UILable,UILable设置为全局变量。

uilabel.frame =CGRectMake(17, 8, cell.contentView.bounds.size.width - side+10, 20); uilabel.text = @"请填写审批意见..."; uilabel.enabled = NO;//lable必须设置为不可用 uilabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:uilabel]; 实现UITextView的代理 -(void)textViewDidChange:(UITextView *)textView { self.examineText = textView.text; if (textView.text.length == 0) { uilabel.text = @"请填写审批意见..."; }else{ uilabel.text = @""; } } 第二种: UITextView 实现 placeholder 及隐藏键盘 #import @interface UIPlaceHolderTextView : UITextView { NSString *placeholder; UIColor *placeholderColor; @private UILabel *placeHolderLabel; } @property(nonatomic, retain) UILabel *placeHolderLabel; @property(nonatomic, retain) NSString *placeholder; @property(nonatomic, retain) UIColor *placeholderColor; -(void)textChanged:(NSNotification*)notification; @end #import "UIPlaceHolderTextView.h" @implementation UIPlaceHolderTextView @synthesize placeHolderLabel; @synthesize placeholder; @synthesize placeholderColor; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [placeHolderLabel release]; placeHolderLabel = nil; [placeholderColor release]; placeholderColor = nil; [placeholder release]; placeholder = nil; [super dealloc]; } - (void)awakeFromNib { [super awakeFromNib]; [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } - (id)initWithFrame:(CGRect)frame { if( (self = [super initWithFrame:frame]) ) { [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } return self; } - (void)textChanged:(NSNotification *)notification { if([[self placeholder] length] == 0) { return; } if([[self text] length] == 0) { [[self viewWithTag:999] setAlpha:1]; } else { [[self viewWithTag:999] setAlpha:0]; } } - (void)setText:(NSString *)text { [super setText:text]; [self textChanged:nil]; } - (void)drawRect:(CGRect)rect { if( [[self placeholder] length] > 0 ) { if ( placeHolderLabel == nil ) { placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8,8,self.bounds.size.width - 16,0)]; placeHolderLabel.lineBreakMode = UILineBreakModeWordWrap; placeHolderLabel.numberOfLines = 0; placeHolderLabel.font = self.font; placeHolderLabel.backgroundColor = [UIColor clearColor]; placeHolderLabel.textColor = self.placeholderColor; placeHolderLabel.alpha = 0; placeHolderLabel.tag = 999; [self addSubview:placeHolderLabel]; } placeHolderLabel.text = self.placeholder; [placeHolderLabel sizeToFit]; [self sendSubviewToBack:placeHolderLabel]; } if( [[self text] length] == 0 && [[self placeholder] length] > 0 ) { [[self viewWithTag:999] setAlpha:1]; } [super drawRect:rect]; } @end //隐藏键盘,实现UITextViewDelegate -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text { if ([text isEqualToString:@" "]) { [m_textView resignFirstResponder]; return NO; } return YES; }

storyboard中定义的view的坐标和大小,用代码改变大小时,是不是改变不了

1. 建一个 UIView的子类(MyView.h/MyView.m) 2. 建一个 View类型的XIB 3. 把xib的file‘s owner设为MyView 4. 在.h文件里加上 @property (nonatomic, retain) IBOutlet UIView *contentView;   5.绑定xib里的根view到.h里的 contentView 6.在.m里加上   - (void)awakeFromNib { NSLog(@"awake from nib"); [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; [self addSubview:self.contentView]; }   ok了。

storyboard里用的时候把UIView的类名改为MyView就可以。

xib和.h可以互相绑定子outlet什么的。

关于控制view的UIView.m类的请教

如果你是用initwithframe创建的view,你就自己写个initwithframe。

- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self;}如果你是用interface builder拽的view,用下面的肯定可以-(void)awakeFromNib{}

有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

返回值如果为0 说明没找到 #import "find.h" @implementation find - (void)awakeFromNib { NSString *str1 = @"tststststssststststst"; NSString *str2 = @"s"; int iCount = [self findTheString:str2 FromString:str1]; NSLog(@"%d",iCount); } - (int)findTheString:(NSString *)str1 FromString:(NSString *)str2 { NSArray *array = [ponentsSeparatedByString:str1]; return [array count] - 1; } @end

酷番云-618云上秒杀,香港1核2M 29/月,高防服务器20M 147/月 50M 450/月,续费同价!

官方网站:点击访问酷番云官网活动方案:优惠方案一(限时秒杀专场)有需要海外的可以看看,比较划算29月,建议年付划算,月付续费不同价,这个专区。国内节点可以看看,性能高IO为主, 比较少见。平常一般就100IO 左右。优惠方案二(高防专场)高防专区主要以高防为主,节点有宿迁,绍兴,成都,宁波等,节点挺多,都支持防火墙自助控制。续费同价以下专场。 优惠方案三(精选物理机)西南地区节点比较划算,赠送5...

Sharktech($49/月),10G端口 32GB内存,鲨鱼机房新用户赠送$50

Sharktech 鲨鱼机房商家我们是不是算比较熟悉的,因为有很多的服务商渠道的高防服务器都是拿他们家的机器然后部署高防VPS主机的,不过这几年Sharktech商家有自己直接销售云服务器产品,比如看到有新增公有云主机有促销活动,一般有人可能买回去自己搭建虚拟主机拆分销售的,有的也是自用的。有看到不少网友在分享到鲨鱼机房商家促销活动期间,有赠送开通公有云主机$50,可以购买最低配置的,$49/月的...

A400互联37.8元/季,香港节点cn2,cmi线路云服务器,1核/1G/10M/300G

A400互联怎么样?A400互联是一家成立于2020年的商家,A400互联是云服务器网(yuntue.com)首次发布的云主机商家。本次A400互联给大家带来的是,全新上线的香港节点,cmi+cn2线路,全场香港产品7折优惠,优惠码0711,A400互联,只为给你提供更快,更稳,更实惠的套餐,香港节点上线cn2+cmi线路云服务器,37.8元/季/1H/1G/10M/300G,云上日子,你我共享。...

awakefromnib为你推荐
bloomfilter如何用Java写一个爬虫fclosefclose / fopen策略组电脑组策略详解电子日历我想做个项目 如何在电子日历中进行时间的选择inode智能客户端inode智能客户端无法正常启动,根本开都开不了smartupload为什么使用smartupload执行上传保存操作时用这句smart.save("upload")失败用smart.save("/upload")成功ruby语言Ruby语言输入方法法系统论坛安卓系统论坛哪个好?mediasres什么意思新手怎么制作表格怎样能学会制作表格
虚拟主机代理 域名查询系统 抗投诉vps主机 187邮箱 西安电信测速 burstnet 流媒体服务器 韩国电信 哈喽图床 抢票工具 12306抢票助手 网通代理服务器 免费smtp服务器 免费个人空间申请 web服务器架设 1g空间 美国堪萨斯 卡巴斯基是免费的吗 安徽双线服务器 免费主页空间 更多