iOS開發之複製字串到剪貼簿

2021-09-11 13:02:48 字數 2547 閱讀 2094

這次需求有複製功能,把字串複製到系統剪貼簿,

1.在 view 裡貼上scrollview 2.在scrollview裡貼上 uitextview,用於上下滑動展示完整資料

// 邀請鏈結

uiview *linkview2 = [[uiview alloc] init];

linkview2.backgroundcolor = [uicolor whitecolor];

linkview2.frame = cgrectmake(0, cgrectgetmaxy(line.frame), ui_view_width, cellh);

[self.view addsubview:linkview2];

// 邀請鏈結label

uilabel *linklabel2 = [[uilabel alloc] init];

linklabel2.backgroundcolor = [uicolor clearcolor];

linklabel2.frame = cgrectmake(marginx, -1, 60, cellh);

linklabel2.text = @"邀請鏈結";

linklabel2.font = setuptextlabelfont;

linklabel2.textcolor = xhhcolor(102, 102, 102);

[linkview2 addsubview:linklabel2];

// 複製按鈕

uibutton *copybtn = [uibutton buttonwithtype:uibuttontypecustom];

[copybtn settitle:@"複製"

forstate:uicontrolstatenormal];

copybtn.frame = cgrectmake(ui_view_width - marginx - btnw, (cellh - btnh) * 0.5, btnw, btnh);

copybtn.titlelabel.font = [uifont systemfontofsize:12];

[copybtn addtarget:self action :@selector(copylinkbtnclick) forcontrolevents:uicontroleventtouchupinside];

copybtn.backgroundcolor = [uicolor whitecolor];

[copybtn settitlecolor:xhhtitlecolor forstate:uicontrolstatenormal];

copybtn.layer.bordercolor = xhhtitlecolor.cgcolor;

copybtn.layer.cornerradius = xhh_btncornerradius;

copybtn.layer.borderwidth = 1.0f;

[linkview2 addsubview:copybtn];

self.copylinkbtn = copybtn;

// 滑動邀請鏈結

uiscrollview *scrollview = [[uiscrollview alloc]initwithframe:cgrectmake(cgrectgetmaxx(linklabel2.frame), 0, ui_view_width - linklabel2.width - btnw - marginx * 2, cellh)];

scrollview.showshorizontalscrollindicator = no;

scrollview.showshorizontalscrollindicator = no;

scrollview.bounces = no;

[linkview2 addsubview:scrollview];

uitextview *link = [[uitextview alloc]initwithframe:cgrectmake(0, 0, ui_view_width - linklabel2.width - btnw - marginx * 2, 50)];

link.text = @"wwww.ujfwegertkyluiopafsdfghnlrjkliop[sdfghjklertyui";

link.textcolor = [uicolor graycolor];

link.textcontainer.maximumnumberoflines = 1;

link.scrollenabled = yes;//是否可以拖動

link.editable = no;//禁止編輯

[scrollview addsubview:link];

scrollview.contentsize = cgsizemake(cgrectgetwidth(link.bounds), 50);

self.link = link;

複製**

/**

* 複製鏈結

*/- (void)copylinkbtnclick

複製**

ios複製到剪貼簿

uipasteboard 這個就是剪貼簿 uipasteboard pastboard uipasteboardgeneralpasteboard pastboard.string self.scanresult lcalerttoastshow 掃瞄結果已複製到剪貼簿 通過名稱獲取貼上板並且移除 ...

vim複製內容到剪貼簿

vim使用過程中需要將內容直接複製到系統剪貼簿,使用場景 在vim編輯過程中,需要將某些內容直接複製,並貼上到部落格或gedit中 在2個視窗中分別用vim編輯,此時無法通過vim操作完成,只能借助系統剪貼簿 首先需要檢查vim是否支援系統剪貼簿 vim version grep clipboard...

JS複製內容到剪貼簿

這裡我只講解乙個辦法,網上找了一大堆全是扯淡!第一步 npm install clipboard polyfill第二步 import clipboard from clipboard polyfill 第三步 clipboard.writetext this text is plain.資料寫到剪...