textField.keyboardAppearance = UIKeyboardAppearanceAlert;
状态栏的网络活动风火轮是否旋转
[UIApplication sharedApplication].networkActivityIndicatorVisible,默认值是NO。
截取屏幕图片
//创建一个基于位图的图形上下文并指定大小为CGSizeMake(200,400)
UIGraphicsBeginImageContext(CGSizeMake(200,400));
//renderInContext 呈现接受者及其子范围到指定的上下文
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//返回一个基于当前图形上下文的图片
UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext();
//移除栈顶的基于当前位图的图形上下文
UIGraphicsEndImageContext();
//以png格式返回指定图片的数据
imageData = UIImagePNGRepresentation(aImage);
更改cell选中的背景
UIView *myview = [[UIView alloc] init];
myview.frame = CGRectMake(0, 0, 320, 47);
myview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"0006.png"]];
cell.selectedBackgroundView = myview;
iPhone键盘改变颜色
只有这2种数字键盘才有效果:UIKeyboardTypeNumberPad,UIKeyboardTypePhonePad
keyboardAppearance = UIKeyboardAppearanceAlert
代码如下:
NSArray *ws = [[UIApplication sharedApplication] windows];
for(UIView *w in ws){
NSArray *vs = [w subviews];
for(UIView *v in vs){
- if([[NSString stringWithUTF8String:object_getClassName(v)] isEqualToString:@"UIKeyboard"]){
- v.backgroundColor = [UIColor redColor];
- }
- }
- }
在父viewController中如下设置:
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]init];
backbutton.title = @"返回列表";
self.navigationItem.backBarButtonItem = backbutton;
[backbutton release];
navigationbar的back键触发其他事件
UIButton *back =[[UIButton alloc] initWithFrame:CGRectMake(200, 25, 63, 30)];
[back addTarget:self act
ion:@selector(reloadRowData:) forControlEvents:UIControlEventTouchUpInside];
[back setImage:[UIImage imageNamed:@"返回按钮.png"] forState:UIControlStateNormal];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem = loginButtonItem
[back release];
[backButtonItem release];
//防止屏幕暗掉锁屏
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
//将图片从左到右翻页效果显示
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 470)];
[imageView setImage:[UIImage imageNamed:@"Bg.jpg"]];
self.myImageView =imageView;
[self.view addSubview:imageView];
[imageView release];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[myImageView setFrame:CGRectMake(0, 0, 310, 470)];
[UIView commitAnimations];
让覆盖在下面层的视图接受触摸事件
searchImage.exclusiveTouch = YES;//第一层
searchImage.userInteractionEnabled = NO;
myMapView.exclusiveTouch = NO;//第二层
myMapView.userInteractionEnabled = YES;
View的缩放
NSValue *touchPointValue = [[NSValue valueWithCGPoint:CGPointMake(100,100)] retain];
[UIView beginAnimations:nil context:touchPointValue];
transform = CGAffineTransformMakeScale(0.1,0.21);
firstPieceView.transform = transform;
[UIView commitAnimations];
点击 UITextView 输入文字,光标都从最初点开始
能让用户点击 UITextView 输入文字时,光标都从最初点开始
- (void)textViewDidChangeSelection:(UITextView *)textView
{
NSRange range;
range.location = 0;
range.length = 0;
textView.selectedRange = range;
}
UITextView光标位置的设置
点击 UITextView 输入文字,光标都从最初点开始
更改UITextView的光标的位置:
-(void)textViewDidChangeSelecti on:(UITextView*)textView
{
NSRange range;
range.location = 0;
range.length = 0;
textView.selectedRange =range;
}
以上是当在UITextView中输入文字的时候,光标都从最初点开始。
UITextView在光标处添加文字
// 获得光标所在的位置
int location =contentTextView.selectedRange.location;
// 将UITextView中的内容进行调整(主要是在光标所在的位置进行字符串截取,再拼接你需要插入的文字即可)
NSString *content = contentTextView.text;
NSString *result = [NSStringstringWithFormat:@"%@[姓名变量]%@",[contentsubstringToIndex:location],[contentsubstringFromIndex:location]];
// 将调整后的字符串添加到UITextView上面
contentTextView.text = result;
如何设置UITextView的光标位置
UITextView * m_textInput;
//设置光标到输入文字的末尾
NSUInteger length = m_textInput.text.length;
m_textInput.selectedRange = NSMakeRange(length,0);
UITextView方法 用法
UITextView限制行数的问题之前试了好多方法,最终解决了,解决方法非常简单,在UITextViewDelegate中加下面的方法即可:
-(BOOL)textView:(UITextView *)textViewshouldChangeTextInRange:(NSRange)range
replacementText:(NSString*)text {
if (textView.contentSize.height > 104){
textView.text = [textView.text substringToIndex:[textView.textlength]-1];
returnNO;
}
return YES;
}
-(void)textViewDidChangeSelection:(UITextView*)textView
每次输入都知道
[textView becomeFirstResponder]
(void)textViewDidChange:(UITextView*)textView 当textView的内容发生改变时,会调用。。再此计算已经输入的字符个数。
- (BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)rangereplacementText:(NSString *)text; {
if([@"\n" isEqualToString:text] == YES) {
[textViewresignFirstResponder];
returnNO;
}
returnYES;
}
- (BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)rangereplacementText:(NSString *)text;
textview根据光标插入数据
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//定位光标
NSRange range = [opinion selectedRange];
NSMutableString *top = [[NSMutableString alloc] initWithString:[opinion text]];
NSString *addName = [NSString stringWithFormat:@"%@、",cell.textLabel.text];
[top insertString:addName atIndex:range.location];
opinion.text = top;
[top release];
用NStimer每隔一定时间刷新界面
NSTimer *addEnemyTimer;
addEnemyTimer=[NSTimer scheduledTimerWithTimeInterval:(3.0) target:self selector:@selector(addEnemy) userInfo:nil repeats:YES];
可以尝试使用一个单独的线程来实现