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

TMThosting:VPS月付55折起,独立服务器9折,西雅图机房,支持支付宝

TMThosting发布了今年黑色星期五的促销活动,即日起到12月6日,VPS主机最低55折起,独立服务器9折起,开设在西雅图机房。这是一家成立于2018年的国外主机商,主要提供VPS和独立服务器租用业务,数据中心包括美国西雅图和达拉斯,其中VPS基于KVM架构,都有提供免费的DDoS保护,支持选择Windows或者Linux操作系统。Budget HDD系列架构CPU内存硬盘流量系统价格单核51...

快云科技:香港沙田CN2云服务器低至29元/月起;美国高防弹性云/洛杉矶CUVIP低至33.6元/月起

快云科技怎么样?快云科技是一家成立于2020年的新起国内主机商,资质齐全 持有IDC ICP ISP等正规商家。云服务器网(yuntue.com)小编之前已经介绍过很多快云科技的香港及美国云服务器了,这次再介绍一下新的优惠方案。目前,香港云沙田CN2云服务器低至29元/月起;美国超防弹性云/洛杉矶CUVIP低至33.6元/月起。快云科技的云主机架构采用KVM虚拟化技术,全盘SSD硬盘,RAID10...

RAKSmart VPS主机半价活动 支持Windows系统 包含香港、日本机房

RAKSmart 商家最近动作还是比较大的,比如他们也在增加云服务器产品,目前已经包含美国圣何塞和洛杉矶机房,以及这个月有新增的中国香港机房,根据大趋势云服务器算是比较技术流的趋势。传统的VPS主机架构方案在技术层面上稍微落后一些,当然也是可以用的。不清楚是商家出于对于传统VPS主机清理库存,还是多渠道的产品化营销,看到RAKSmart VPS主机提供美国、香港和日本机房的半价促销,当然也包括其他...

awakefromnib为你推荐
ipad怎么分屏ipad怎样分屏操作系统混淆矩阵两个矩阵相似可以得出什么一物一码一码归一码的上句是什么?linux修改文件名Linux中,怎样修改文件名?开票系统防伪税控开票系统怎么安装?tvosairpods什么意思 airpods连接方式是怎样的民生电商民生电商与传统的电商有什么区别?faq是什么意思在国际贸易中“FAQ”代表的是什么意思中文搜索引擎百度是不是全球最大中文搜索引擎?新手怎么制作表格怎样能学会制作表格
虚拟主机试用 域名批量查询 网游服务器租用 vps服务器 企业域名备案 com域名抢注 西安服务器 l5520 512au info域名 免费ftp站点 php空间推荐 双十一秒杀 美国堪萨斯 中国网通测速 服务器监测 免费网页申请 1元域名 中国电信测速网站 免费asp空间申请 更多