iOS get screen size

0 意見


CGRect screenSize = [[UIScreen mainScreen] applicationFrame];



iOS move view

0 意見


[BackgroundView addSubview:hint];
[self.view addSubview:BackgroundView];
[BackgroundView moveTo:CGPointMake(0, 0) duration:0.6 option:UIViewAnimationOptionCurveEaseInOut];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(removeHintBanner) userInfo:nil repeats:NO];

- (void) removeHintBanner
{
    [BackgroundView moveTo:CGPointMake(0, -15) duration:1.2 option:UIViewAnimationOptionCurveEaseInOut];
}

iOS view transition view

0 意見

[UIView transitionWithView:self.view duration:0.5
                       options:UIViewAnimationOptionTransitionCurlDown //change to whatever animation you like
                    animations:^ { [self.view addSubview:BackgroundView]; }
                    completion:nil];

iOS integer only in textfield

0 意見

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *textValue = textField.text;
    //NSString *firstChar = [textValue substringWithRange:NSMakeRange(0, 1)];
    
    UITextRange *selRange = textField.selectedTextRange;
    UITextPosition *selStartPos = selRange.start;
    NSInteger idx = [textField offsetFromPosition:textField.beginningOfDocument toPosition:selStartPos];
    NSCharacterSet *nonNumberSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
    return ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0) || [string isEqualToString:@""] || (idx == 0 && [string isEqualToString:@"-"]);
    
    return YES;
}

iOS getting the cursor position of UITextField

0 意見

UITextRange *selRange = textField.selectedTextRange;
UITextPosition *selStartPos = selRange.start;
NSInteger idx = [textField offsetFromPosition:textField.beginningOfDocument toPosition:selStartPos];

iOS back to last view or navigator

0 意見

//back to last view
[self dismissModalViewControllerAnimated:YES];

// back to navigation
[self.navigationController popViewControllerAnimated:YES];

Android align message to center in alertDialog

0 意見

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("It is title");
alert.setMessage("hey");
alert.setPositiveButton("Ok", null);
     
AlertDialog dialog = alert.show();
TextView tv_message = (TextView)dialog.findViewById(android.R.id.message);
tv_message.setGravity(Gravity.CENTER);
dialog.show();