Skip to content

Instantly share code, notes, and snippets.

@5ZSQ
5ZSQ / gist:f84e1f94a2633a200d147f55ca79a21f
Created May 23, 2017 11:19
iOS - NSString拼接字符串
NSString* string; // 结果字符串
NSString* string1, string2; //已存在的字符串,需要将string1和string2连接起来
//方法1.
string = [NSString initWithFormat:@"%@,%@", string1, string2 ];  
//方法2.
string = [string1 stringByAppendingString:string2];
//方法3 .
string = [string stringByAppendingFormat:@"%@,%@",string1, string2];
@5ZSQ
5ZSQ / gist:cbc6d561753859921a00dbca8d571452
Created May 31, 2017 01:15
iOS - 颜色值#ffffff转UIColor
+ (UIColor*)colorWithHexString:(NSString*)stringToConvert{
if([stringToConverthasPrefix:@"#"])
{
stringToConvert = [stringToConvertsubstringFromIndex:1];
}
NSScanner*scanner = [NSScannerscannerWithString:stringToConvert];
unsignedhexNum;
if(![scannerscanHexInt:&hexNum])
{
returnnil;
@5ZSQ
5ZSQ / gist:c91bd5f03a259ac5ab01a72f834255ed
Created May 31, 2017 02:41
iOS - 为UILabel设置点击事件
// 1. 创建一个点击事件,点击时触发labelClick方法
UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
// 2. 将点击事件添加到label上
label addGestureRecognizer:labelTapGestureRecognizer];
label.userInteractionEnabled = YES; // 可以理解为设置label可被点击
// 3. 在此方法中设置点击label后要触发的操作
@5ZSQ
5ZSQ / IpUtils.java
Created June 5, 2017 01:38
Android - 获取ip地址
/*获取设备IPv4地址对应的字符串*/
public static String getIpAddressString() {
try {
for (Enumeration<NetworkInterface> enNetI = NetworkInterface
.getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
NetworkInterface netI = enNetI.nextElement();
for (Enumeration<InetAddress> enumIpAddr = netI
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
@5ZSQ
5ZSQ / gist:b5ea90b702b9fe5b44675b71bd24334d
Created June 6, 2017 07:32
iOS - cocoapod update跳过更新库命令
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
I use the first
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
@5ZSQ
5ZSQ / gist:cb7392b42fd45d546a6732fd2076a4de
Created June 7, 2017 10:01
iOS - webview [Objectc-js]通信
>使用 `WebViewJavascriptBridge`库
/*这段代码是固定的,必须要放到js中*/
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
@5ZSQ
5ZSQ / NetWork.m
Created June 15, 2017 08:25
iOS - 实时监控网络状态
//实时监控网络状态
- (void)KVONetworkChange {
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:{
@5ZSQ
5ZSQ / CommonUtil.java
Last active September 29, 2017 01:49
Android通用工具类 - CommonUtil.java
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.SharedPreferences;
@5ZSQ
5ZSQ / gist:18f0b3b17f42d96fecb82c51bc056740
Created June 27, 2017 07:16
iOS - 使用Core Animation中的CATranstion实现背景自然渐变
NSString *imgUrl = _dataArray[index][@"url"]; //下一张背景图url
UIImage *placeHolder = _baseImgView.image; //使用上一张背景图作为placeholder
[_baseImgView sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:placeHolder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image)
CATransition *transition = [CATransition animation];
transition.type = kCATransitionFade;
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[_baseImgView.layer addAnimation:transition forKey:nil];