OC 项目中遇到的一些知识总结

1. 自定义导航条的标题(文字大小和颜色)

直接上代码

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:17];
    titleLabel.textAlignment = NSTextAlignmentCenter;

    titleLabel.text=@"登录";
    self.navigationItem.titleView = titleLabel;

2. 设置textField的左边图片

直接上代码

    self.textFiled.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_login_shouji"]];
    self.textFiled.leftViewMode = UITextFieldViewModeAlways;

3. 设置textfield的placeholder颜色

直接上代码


self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.loginInputId.placeholder attributes:@{NSForegroundColorAttributeName: color}];

4. 判断输入法是否是中文

怒上代码 中文是zh-cn,应为是en-us,其他地区见
地区代码

 BOOL isChinese = [[[UIApplication sharedApplication] textInputMode].primaryLanguage isEqualToString:@"zh-cn"];

5. fullResolutionImage 与fullScreenImage

参考自使用ALAssetsLibrary读取所有照片
ALAssetRepresentation的 metadata 方法很慢,我在iPhone4 iOS5.1.1中测试,此方法返回需要40-50ms,所以获取图片的个各种属性尽量直接从ALAssetRepresentation中获取,不要读取metadata,调用多次也确实很容易会memory warning,

系统”相册”程序显示的图片是 fullScreenImage ,而不是 fullResolutionImage ,fullResolutionImage尺寸太大,在手机端显示推荐用fullScreenImage。
fullScreenImage已被调整过方向,可直接使用,即

[UIImage imageWithCGImage:representation.fullScreenImage];

使用fullResolutionImage要自己调整方法和scale,即

[UIImage imageWithCGImage:representation.fullResolutionImage scale:representation.scale orientation:representation.orientation];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React Native 是一款基于 JavaScript 的框架,可以帮助我们快速开发 iOS 和 Android 应用程序。如果你想将 React Native 集成进你的现有 iOS 项目,可以按照以下步骤进行操作: 1. 创建一个新的 React Native 项目 首先,你需要在你的电脑上安装好 React Native 开发环境。接着,在终端输入以下命令创建一个新的 React Native 项目: ``` npx react-native init MyReactNativeApp ``` 2. 将 React Native 项目的 jsCodeLocation 文件复制到 iOS 项目 在 React Native 项目的 ios 目录下,你会找到一个名为 MyReactNativeApp.xcodeproj 的 Xcode 项目文件。打开该文件,然后将 jsCodeLocation 文件夹的 main.jsbundle 文件和 index.js 文件复制到你的 iOS 项目。 3. 在 iOS 项目添加 React Native 依赖库 在你的 iOS 项目,你需要添加以下依赖库: - libRCTWebSocket.a - libfishhook.a - libcxxreact.a - libReact.a 你可以通过 CocoaPods 或手动添加库的方式来完成此操作。如果你使用 CocoaPods,只需要在 Podfile 添加以下代码: ``` pod 'React', :path => '../node_modules/react-native', :subspecs => [ 'Core', 'CxxBridge', 'DevSupport', 'RCTText', 'RCTNetwork', 'RCTWebSocket', 'RCTAnimation', 'RCTImage', 'RCTLinkingIOS', 'RCTSettings', 'RCTVibration', 'RCTActionSheet', 'RCTBlob', 'RCTGeolocation', 'RCTPushNotification', 'RCTStatusBar', 'RCTCameraRoll' ] ``` 然后在终端运行以下命令: ``` pod install ``` 如果你手动添加库,可以在 Build Phases 添加以下库: - libRCTWebSocket.a - libfishhook.a - libcxxreact.a - libReact.a 4. 在 iOS 项目添加 React Native 模块 如果你想在 iOS 项目使用 React Native 模块,你需要将其添加到你的 iOS 项目。具体操作方式可以参考 React Native 官方文档的说明。 5. jsCodeLocation 生成方式总结 在 React Native 项目,你可以通过以下两种方式生成 jsCodeLocation: - 手动生成 在终端输入以下命令: ``` react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios ``` 该命令会生成一个名为 main.jsbundle 的文件,该文件就是 jsCodeLocation。 - 自动更新 在 Xcode 项目,你可以使用 RCTBundleURLProvider 类来动态生成 jsCodeLocation。该类会根据当前环境生成不同的 jsCodeLocation,例如在开发环境,它会生成一个指向本地服务器的 jsCodeLocation。在生产环境,它会生成一个指向发布的 jsCodeLocation。在使用 RCTBundleURLProvider 类之前,你需要先在 AppDelegate.m 文件导入该类: ``` #import <React/RCTBundleURLProvider.h> ``` 然后,在 didFinishLaunchingWithOptions 方法添加以下代码: ``` NSURL *jsCodeLocation; #ifdef DEBUG jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"MyReactNativeApp" initialProperties:nil launchOptions:launchOptions]; ``` 以上代码会根据当前环境生成不同的 jsCodeLocation。在开发环境,它会生成一个指向本地服务器的 jsCodeLocation。在生产环境,它会生成一个指向发布的 jsCodeLocation。 以上就是将 React Native 集成进现有 iOS 项目的过程记录。如果你想了解更多关于 React Native 的知识,可以参考 React Native 官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值