晃动设备、读取本地的Html文件、避免cell子视图的重用,分享到Facebook Twitter

来源:互联网 发布:怎么买氰化钾 淘宝 编辑:程序博客网 时间:2024/04/29 19:57

IOS系统所有的字体调用                                                                                                                                                                          NSLog(@"familyNames==%@   fontNamesForFamilyName=%@",[UIFont familyNames],[UIFont fontNamesForFamilyName:@"Helvetica Neue"]);

Example :计时器格式的字体    [UIFont fontWithName:@"DB LCD Temp" size:100.0]


把程序内容分享到社交网站上Facebook,Twitter上

 SLComposeViewController *tweetViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    NSString *total = [DragData doMeditationTime:[log.meditationTime timeIntervalSinceReferenceDate]];

    NSString *interval = [DragData doMeditationTime:[log.interval timeIntervalSinceReferenceDate]];

    

    NSString *twitterStr = [NSString stringWithFormat:@"Finished my meditation, %@ in total, %@ an interval.",total, interval];

    [tweetViewController setInitialText:twitterStr];

    [tweetViewController addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/meditation-timer-for-ipad/id514271769?mt=8"]];

    

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)

    {

        [tweetViewController dismissViewControllerAnimated:YES completion:^{

            

        }];

    };

    [tweetViewController setCompletionHandler:myBlock];

    if (tweetViewController == nil)

    {

        UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"No Twitter account" message:@"There is no Twitter account configured. You can add or create a Twitter account in Settings." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alert show];

        return;

    }else

    {

        [self presentViewController:tweetViewController animated:YES completion:nil];

    }

statusBar消失的问题    解决方法在 info------>View controller-based status bar appearance  设为YES


关于cell的重用问题,防止在cell上加载多次子视图

  UIImageView *imageView=(UIImageView *)[cell viewWithTag:111111];


 if (![cell viewWithTag:111111])

    {

        imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(00512670)] autorelease];

        imageView.tag=111111;

        [cell addSubview:imageView];

    }

获取工程中一个素材或者文件的绝对路径

  path=[[NSBundle mainBundlepathForResource:[self.imageArray objectAtIndex:indexPath.rowofType:@"jpg"];

去除字符串中的空格

NSString *trimedString = [self.nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


晃动设备可随机切换图片

 CMMotionManager   *manager = [[CMMotionManageralloc]init];

    manager.accelerometerUpdateInterval=1.0/5.0;

    [managerstartAccelerometerUpdates];

    [managerstartAccelerometerUpdatesToQueue:[NSOperationQueuemainQueue] withHandler:^(CMAccelerometerData *accelerometerData,NSError *error) {

        if (fabsf(manager.accelerometerData.acceleration.x) > 1.5 || fabsf(manager.accelerometerData.acceleration.y) >1.5 || fabsf(manager.accelerometerData.acceleration.z) >1.5)

        {

             [selfsetBackgroundViewIsShake:YES];  //响应方法摇动设备时调用

        }

    }];


读取本地的Html文件进行显示

   NSString *path = [[NSBundlemainBundle] pathForResource:@"meditation_help_ipad"ofType:@"html"];

    NSFileHandle *readHandle = [NSFileHandlefileHandleForReadingAtPath:path];

    NSString *htmlString = [[NSStringalloc] initWithData

                            [readHandle readDataToEndOfFile]encoding:NSUTF8StringEncoding];

    self.view.backgroundColor=kBackgroundColor;

   UIWebView *webView=[[UIWebView alloc]init];

   webView.opaque =NO;

    webView.backgroundColor = [UIColorclearColor];

    [webViewloadHTMLString:htmlStringbaseURL:nil];

    [self.view addSubview:webView];
0 0
原创粉丝点击